Skip to content

fix: default anthropic message type to text when missing - #42203

Open
abhijeetnardele24-hash wants to merge 2 commits into
appsmithorg:releasefrom
abhijeetnardele24-hash:fix/issue-36245
Open

fix: default anthropic message type to text when missing#42203
abhijeetnardele24-hash wants to merge 2 commits into
appsmithorg:releasefrom
abhijeetnardele24-hash:fix/issue-36245

Conversation

@abhijeetnardele24-hash

@abhijeetnardele24-hash abhijeetnardele24-hash commented Sep 7, 2026

Copy link
Copy Markdown

Description

This PR fixes a bug in the Anthropic AI integration where switching the query mode from "Chat" to "Vision" resulted in a "content not found" error during query execution.

Root cause:
The frontend carries over the messages array data when switching from chat.json to vision.json. Since the CHAT message schema does not contain the type field, the resulting JSON array lacks it. However, VisionCommand.java strictly expected type to be either text or image. When it encountered a null/missing type, it failed to populate the message content, resulting in a malformed payload and a "content not found" error from the Anthropic API.

Fix:
Updated VisionCommand.java to default a missing or empty type to text. This ensures robust parsing and seamlessly handles the payload carried over from the "Chat" command.

Fixes #36245

Type of change

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

  • Verified mvn test passes for anthropicPlugin.
  • The logic safely falls back to text for undefined types in Anthropic Vision messages.

Summary by CodeRabbit

  • Bug Fixes
    • OAuth 2.0 forms now display the expiration setting only for Authorization Code flows.
    • Messages without a specified content type are handled as text, improving compatibility with vision-enabled requests.

@abhijeetnardele24-hash
abhijeetnardele24-hash requested a review from a team as a code owner September 7, 2026 19:35
Copilot AI lite review requested due to automatic review settings September 7, 2026 19:35

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@github-actions github-actions Bot added awaiting-maintainer The next action on this pull request belongs to an Appsmith maintainer external-contribution Pull request submitted from outside the Appsmith repository labels Sep 7, 2026
@github-actions

github-actions Bot commented Sep 7, 2026

Copy link
Copy Markdown

Thanks for contributing to Appsmith!

Credential-free formatting, lint, type, and unit checks will run after GitHub's workflow approval. An Appsmith maintainer will start privileged integration tests or a deploy preview when needed.

No action is required from you while this PR has the awaiting-maintainer label.

@coderabbitai

coderabbitai Bot commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Team

Run ID: 09b825eb-8bb4-4e9d-ad86-276a95f0cf8e

📥 Commits

Reviewing files that changed from the base of the PR and between af38a79 and 1a84da6.

📒 Files selected for processing (2)
  • app/client/src/pages/Editor/DataSourceEditor/RestAPIDatasourceForm.tsx
  • app/server/appsmith-plugins/anthropicPlugin/src/main/java/com/external/plugins/commands/VisionCommand.java

Included review availability: Your plan provides up to 10 included reviews per hour; 8 remain after this review.


Walkthrough

The OAuth form now shows expiresIn only for Authorization Code grants. Anthropic vision processing defaults messages without a type to TEXT.

Changes

OAuth form rendering

Layer / File(s) Summary
Conditional OAuth expiration field
app/client/src/pages/Editor/DataSourceEditor/RestAPIDatasourceForm.tsx
The shared OAuth form detects Authorization Code grants and conditionally renders authentication.expiresIn. The Authorization Code-specific duplicate field is removed.

Vision message handling

Layer / File(s) Summary
Default vision message type
app/server/appsmith-plugins/anthropicPlugin/src/main/java/com/external/plugins/commands/VisionCommand.java
Messages without a type now default to TEXT before processing.

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: ⚪ Minimal · up to 1a84d

Vision queries now process retained chat messages as text when no type is present, and OAuth expiration settings are shown only for Authorization Code grants. No current merge-blocking risk is identified.

Suggested reviewers: sebastianiv21

Poem

OAuth fields now follow the grant
Vision text gets a type to stand
Empty labels no longer stray
Queries find their words each day
Two small fixes keep flows in play

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Out of Scope Changes check ⚠️ Warning The OAuth rendering changes in RestAPIDatasourceForm.tsx are unrelated to the Anthropic Chat-to-Vision issue and the stated PR objectives. Remove the unrelated OAuth changes from this pull request, or link and document a separate objective and issue that require them.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the main change: defaulting missing Anthropic message types to text.
Description check ✅ Passed The description explains the bug, root cause, fix, linked issue, change type, and testing. It does not select a validation checkbox or provide a communication decision, but the core description is com…
Linked Issues check ✅ Passed The change in VisionCommand.java addresses issue #36245 by treating missing message types as text, allowing chat messages carried into Vision mode to produce valid content.
  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

Warning

⚠️ This pull request shows signs of AI-generated slop (description_diff_mismatch). It has been flagged by CodeRabbit slop detection and should be reviewed carefully.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting-maintainer The next action on this pull request belongs to an Appsmith maintainer external-contribution Pull request submitted from outside the Appsmith repository

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Datasource query page field issue with different type of sommands

2 participants