Skip to content

CAMEL-23463: camel-aws-bedrock - reject non-text models in invokeTextModel with a clear error#24252

Merged
oscerd merged 1 commit into
apache:mainfrom
oscerd:fix/CAMEL-23463
Jun 25, 2026
Merged

CAMEL-23463: camel-aws-bedrock - reject non-text models in invokeTextModel with a clear error#24252
oscerd merged 1 commit into
apache:mainfrom
oscerd:fix/CAMEL-23463

Conversation

@oscerd

@oscerd oscerd commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

What

BedrockProducer#setResponseText (reached only via the invokeTextModel operation) switches on modelId to extract text from the model response. Several model IDs advertised as valid in BedrockConfiguration.modelId's @UriParam(enums=...) are not text-generation models (image, embedding, rerank, video/speech). They fell through to the default branch and threw a confusing IllegalStateException("Unexpected model: <modelId>"), even though the model is well known — it simply isn't a text model.

Fixes CAMEL-23463.

How

Replace the catch-all default for these declared-but-non-text models with explicit, categorized cases that fail fast with an actionable IllegalArgumentException:

Category Models Message points to
Image amazon.titan-image-generator-v1, amazon.titan-image-generator-v2:0, amazon.nova-canvas-v1:0, all stability.* invokeImageModel
Embedding amazon.titan-embed-text-v1, amazon.titan-embed-image-v1, cohere.embed-english-v3, cohere.embed-multilingual-v3 invokeEmbeddingsModel
Rerank amazon.rerank-v1:0, cohere.rerank-v3-5:0 (not supported by invokeTextModel)
Video/Speech amazon.nova-reel-v1:0, amazon.nova-reel-v1:1, amazon.nova-sonic-v1:0 (not supported by invokeTextModel)

A genuinely unknown modelId still throws IllegalStateException("Unexpected model: ...").

Why a clear error instead of auto-routing

The Jira issue offered two options (auto-route to the right operation, or validate/document). This PR takes the clear-error route because:

  • The operation is explicitly chosen by the user (URI or CamelAwsBedrockOperation header); silently overriding it would be surprising.
  • Each operation has a different response contract (invokeTextModel extracts text, invokeImageModel extracts the images node, invokeEmbeddingsModel returns the raw response) — auto-routing would break the contract of the operation the user asked for.
  • Rerank/video/speech models have no corresponding operation, so auto-routing cannot cover them anyway.

The check stays at response time (where the old exception was thrown) rather than endpoint creation, because the operation can be overridden per message via CamelAwsBedrockOperation, so the model/operation pairing isn't reliably known at endpoint creation.

Tests

BedrockInvokeTextModelUnsupportedModelTest (mocked BedrockRuntimeClient, no AWS access):

  • Parameterized over all 16 non-text models — asserts an IllegalArgumentException naming the offending model and the invokeTextModel operation, and pointing to invokeImageModel / invokeEmbeddingsModel where a dedicated operation exists.
  • Happy-path test confirming a text model (amazon.titan-text-express-v1) still works.

Docs

Added a short note to aws-bedrock-component.adoc clarifying that the operation must match the model type.


Claude Code on behalf of Andrea Cosentino

🤖 Generated with Claude Code

…Model with a clear error

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Signed-off-by: Andrea Cosentino <ancosen@gmail.com>
@oscerd oscerd requested review from Croway, davsclaus and gnodet June 25, 2026 13:26
@github-actions

Copy link
Copy Markdown
Contributor

🌟 Thank you for your contribution to the Apache Camel project! 🌟
🤖 CI automation will test this PR automatically.

🐫 Apache Camel Committers, please review the following items:

  • First-time contributors require MANUAL approval for the GitHub Actions to run
  • You can use the command /component-test (camel-)component-name1 (camel-)component-name2.. to request a test from the test bot although they are normally detected and executed by CI.
  • You can label PRs using skip-tests and test-dependents to fine-tune the checks executed by this PR.
  • Build and test logs are available in the summary page. Only Apache Camel committers have access to the summary.

⚠️ Be careful when sharing logs. Review their contents before sharing them publicly.

@davsclaus davsclaus 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.

Clean, well-scoped PR. All 16 non-text models from BedrockModels are covered by the new rejection cases with correct model ID strings. Tests are thorough (parameterized over all 16 + happy-path), documentation is clear, and the design rationale (clear error over auto-routing) is sound.

One minor observation: amazon.titan-embed-text-v2:0 remains in the text-model section (line 282, from CAMEL-20765) while titan-embed-text-v1 is now rejected as an embedding model. This is consistent with existing behavior and likely intentional, but worth a note if so.

This review was generated by an AI agent and may contain inaccuracies. Please verify all suggestions before applying.

@github-actions

Copy link
Copy Markdown
Contributor

🧪 CI tested the following changed modules:

  • components/camel-aws/camel-aws-bedrock
All tested modules (8 modules)
  • Camel :: AWS2 Bedrock
  • Camel :: JBang :: MCP
  • Camel :: JBang :: Plugin :: Route Parser
  • Camel :: JBang :: Plugin :: TUI
  • Camel :: JBang :: Plugin :: Validate
  • Camel :: Launcher :: Container
  • Camel :: YAML DSL :: Validator
  • Camel :: YAML DSL :: Validator Maven Plugin

⚙️ View full build and test results

@oscerd oscerd merged commit 016eea1 into apache:main Jun 25, 2026
6 checks passed
@oscerd oscerd deleted the fix/CAMEL-23463 branch July 13, 2026 12:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants