-
Notifications
You must be signed in to change notification settings - Fork 193
fixes structured output for bedrock #1372
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
📝 WalkthroughSummary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings. WalkthroughThis PR adds structured output support for Bedrock streaming by intercepting tool-use events and converting them to content deltas. Additionally, it removes tool call content transformation logic from litellmcompat and bumps versions across the core and plugin stack. Changes
Sequence DiagramsequenceDiagram
participant Client
participant BedrockProvider as Bedrock Provider
participant BedrockAPI as Bedrock API
participant StructOutput as Structured Output Handler
Client->>BedrockProvider: ChatCompletion with structured_output
BedrockProvider->>BedrockAPI: Send request
BedrockAPI-->>BedrockProvider: ToolUse response (tool_calls)
alt Streaming Path
loop For each ToolUse delta
BedrockAPI-->>BedrockProvider: ToolUse.Delta
BedrockProvider->>StructOutput: Accumulate delta
end
StructOutput->>BedrockProvider: Convert accumulated deltas to content
BedrockProvider->>BedrockProvider: Override finish_reason: tool_calls → stop
BedrockProvider-->>Client: Content chunk (not tool_call event)
else Non-Streaming Path
BedrockProvider->>StructOutput: Process tool_calls in response
StructOutput->>BedrockProvider: Extract content from tool_calls
BedrockProvider->>BedrockProvider: Override finish_reason: tool_calls → stop
BedrockProvider-->>Client: ChatCompletion with content
end
Estimated Code Review Effort🎯 4 (Complex) | ⏱️ ~50 minutes Possibly Related PRs
Suggested Reviewers
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Comment |
🧪 Test Suite AvailableThis PR can be tested by a repository admin. |
2353e0d to
52d3053
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@framework/changelog.md`:
- Line 1: The changelog entry "chore: upgrades core to 1.3.11" in
framework/changelog.md is unrelated to this PR; remove that line or replace it
with a concise, accurate entry describing the Bedrock structured output handling
changes (mention Bedrock provider improvements/structured output handling) and
ensure the entry follows the repo's changelog style and formatting.
🧹 Nitpick comments (2)
core/providers/bedrock/bedrock.go (2)
809-817: Consider normalizing finish reasons across all choices.
OnlyChoices[0]gets the structured-output override today; ifn > 1, other choices can still surfacetool_calls. Looping through the slice keeps behavior consistent.Suggested adjustment
- if len(bifrostResponse.Choices) > 0 && bifrostResponse.Choices[0].FinishReason != nil { - if *bifrostResponse.Choices[0].FinishReason == string(schemas.BifrostFinishReasonToolCalls) { - bifrostResponse.Choices[0].FinishReason = schemas.Ptr(string(schemas.BifrostFinishReasonStop)) - } - } + for i := range bifrostResponse.Choices { + if bifrostResponse.Choices[i].FinishReason != nil && + *bifrostResponse.Choices[i].FinishReason == string(schemas.BifrostFinishReasonToolCalls) { + bifrostResponse.Choices[i].FinishReason = schemas.Ptr(string(schemas.BifrostFinishReasonStop)) + } + }
898-1046: Verify structured-output accumulation doesn’t mask later tool calls.
isAccumulatingStructuredOutputis never reset. If Bedrock can emit multipletool_useblocks in a stream (e.g., user tools + structured output), later tool-use deltas would be coerced into content. Please confirm Bedrock stream semantics; if multiple blocks are possible, consider tracking the tool-use ID and clearing the flag on the tool-use stop event.

Summary
Added support for structured outputs in Bedrock provider by properly converting response_format to tool calls and intercepting tool responses to present them as content.
Changes
Type of change
Affected areas
How to test
Breaking changes
Related issues
Improves structured output support across providers.
Security considerations
No security implications.
Checklist