fix: filter empty/whitespace text content blocks at provider boundaries#11877
fix: filter empty/whitespace text content blocks at provider boundaries#11877
Conversation
Why targeted provider-level fixes instead of upstream changesWe initially explored a broader approach (see #11808) that modified the shared message filtering/compilation layer ( We opted against that because:
Instead, this PR adds |
Documentation ReviewNo documentation updates are needed for this PR. Reasoning:
The existing documentation for Anthropic and Bedrock providers remains accurate and complete. |
Test Coverage ReviewThis PR introduces a bug fix to filter out empty/whitespace-only text content blocks across multiple provider implementations. Per testing guidelines, bug fixes should include regression tests. Missing Test Coverage1.
|
Skip empty and whitespace-only text content blocks at each provider's message conversion layer, preventing 400 errors from Anthropic, Bedrock, Venice, and other OpenAI-compatible APIs. - Anthropic: check .trim() instead of truthiness in convertMessageContentToBlocks - Bedrock (core): skip empty text in _convertMessageContentToBlocks - Bedrock (adapter): skip empty text parts in user message conversion - OpenAI adapter: filter empty text parts from assistant array content Fixes #9232, #9765, #9767, #10148, #10293, #10504, #10804, #11045, #11264, #11446, #11497, #11728
f5ccba2 to
64b65a2
Compare
Summary
Skip empty and whitespace-only text content blocks at each provider's message conversion layer, preventing 400 errors from Anthropic and Bedrock.
3 targeted changes, +14/-5 lines, zero upstream behavioral changes.
Changes
core/llm/llms/Anthropic.ts.trim()check inconvertMessageContentToBlockscore/llm/llms/Bedrock.ts_convertMessageContentToBlockspackages/openai-adapters/src/apis/Bedrock.tsWhat this does NOT change
messages.ts,countTokens.ts, ortoResponsesInput" "fallbacks for string content are untouchedtoChatMessageconversionIssues fixed
Fixes #9765, fixes #9767, fixes #10148, fixes #10804, fixes #11045, fixes #11264, fixes #11446, fixes #11497
Test plan
openaiTypeConverters.test.ts— 24/24 pass