CAMEL-23463: camel-aws-bedrock - reject non-text models in invokeTextModel with a clear error#24252
Conversation
…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>
|
🌟 Thank you for your contribution to the Apache Camel project! 🌟 🐫 Apache Camel Committers, please review the following items:
|
davsclaus
left a comment
There was a problem hiding this comment.
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.
|
🧪 CI tested the following changed modules:
All tested modules (8 modules)
|
What
BedrockProducer#setResponseText(reached only via theinvokeTextModeloperation)switches onmodelIdto extract text from the model response. Several model IDs advertised as valid inBedrockConfiguration.modelId's@UriParam(enums=...)are not text-generation models (image, embedding, rerank, video/speech). They fell through to thedefaultbranch and threw a confusingIllegalStateException("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
defaultfor these declared-but-non-text models with explicit, categorized cases that fail fast with an actionableIllegalArgumentException:amazon.titan-image-generator-v1,amazon.titan-image-generator-v2:0,amazon.nova-canvas-v1:0, allstability.*invokeImageModelamazon.titan-embed-text-v1,amazon.titan-embed-image-v1,cohere.embed-english-v3,cohere.embed-multilingual-v3invokeEmbeddingsModelamazon.rerank-v1:0,cohere.rerank-v3-5:0invokeTextModel)amazon.nova-reel-v1:0,amazon.nova-reel-v1:1,amazon.nova-sonic-v1:0invokeTextModel)A genuinely unknown
modelIdstill throwsIllegalStateException("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:
CamelAwsBedrockOperationheader); silently overriding it would be surprising.invokeTextModelextracts text,invokeImageModelextracts theimagesnode,invokeEmbeddingsModelreturns the raw response) — auto-routing would break the contract of the operation the user asked for.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(mockedBedrockRuntimeClient, no AWS access):IllegalArgumentExceptionnaming the offending model and theinvokeTextModeloperation, and pointing toinvokeImageModel/invokeEmbeddingsModelwhere a dedicated operation exists.amazon.titan-text-express-v1) still works.Docs
Added a short note to
aws-bedrock-component.adocclarifying that the operation must match the model type.Claude Code on behalf of Andrea Cosentino
🤖 Generated with Claude Code