Skip to content

Conversation

@akshaydeo
Copy link
Contributor

@akshaydeo akshaydeo commented Jan 19, 2026

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

  • Enhanced structured output tests to verify content is non-empty
  • Added Bedrock-specific assertions to ensure tool calls and function calls don't leak through
  • Implemented structured output handling in Bedrock provider by:
    • Intercepting tool calls for the structured output tool
    • Converting tool use deltas to content deltas in streaming responses
    • Accumulating structured output content properly
  • Enabled structured output tests for Bedrock provider

Type of change

  • Feature
  • Bug fix

Affected areas

  • Core (Go)
  • Providers/Integrations

How to test

# Run Bedrock provider tests
go test ./core/providers/bedrock/...

# Run structured output tests specifically
go test -run TestStructuredOutput ./core/providers/bedrock/...

Breaking changes

  • No

Related issues

Improves structured output support across providers.

Security considerations

No security implications.

Checklist

  • I added/updated tests where appropriate
  • I verified builds succeed (Go)
  • I verified the CI pipeline passes locally

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 19, 2026

📝 Walkthrough

Summary by CodeRabbit

  • Bug Fixes

    • Fixed Bedrock streaming support for structured output
    • Resolved tool call leakage in structured output responses
  • Tests

    • Added comprehensive validations to ensure tool calls do not appear in structured output
  • Chores

    • Updated core to 1.3.11, framework to 1.2.12, and multiple plugin versions

✏️ Tip: You can customize this high-level summary in your review settings.

Walkthrough

This 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

Cohort / File(s) Summary
Bedrock Structured Output Support
core/providers/bedrock/bedrock.go
Adds post-processing in ChatCompletion and ChatCompletionStream to intercept tool-use events when structured output is enabled. Tool calls are converted to content chunks, and finish reasons are overridden from tool_calls to stop. Includes latency tracking and raw response handling for streaming path.
Type Definitions
core/schemas/chatcompletions.go
Introduces BifrostFinishReason type with three constants: BifrostFinishReasonStop, BifrostFinishReasonLength, and BifrostFinishReasonToolCalls.
Test Enhancements
core/internal/testutil/structured_outputs.go
Adds runtime validations for structured outputs across multiple test paths: non-empty content checks, Bedrock-specific assertions to verify no tool calls leak into structured output, and JSON field validation (action, reason, target_node_id, priority).
Test Configuration
core/providers/bedrock/bedrock_test.go
Enables StructuredOutputs: true in TestBedrock configuration.
Documentation
core/providers/bedrock/utils.go
Adds reference URL documentation comment above convertResponseFormatToTool function.
litellmcompat Plugin Refactoring
plugins/litellmcompat/main.go
Removes call to transformToolCallContentResponse in PostHook, directly applying transformTextToChatResponse instead.
litellmcompat Removed Logic
plugins/litellmcompat/toolcallcontent.go
Entire file deleted, removing transformToolCallContentResponse, isContentEmpty, and buildContentFromToolCalls functions that previously populated chat response content from tool call arguments.
Version & Changelog Updates
core/version, core/changelog.md, framework/version, framework/changelog.md, plugins/\\*/version, plugins/\\*/changelog.md, transports/version, transports/changelog.md
Core bumped 1.3.10→1.3.11, Framework 1.2.11→1.2.12, litellmcompat 0.0.1→0.0.2, governance 1.4.12→1.4.13, jsonparser 1.4.11→1.4.12, logging 1.4.11→1.4.12, maxim 1.5.10→1.5.11, mocker 1.4.11→1.4.12, otel 1.1.11→1.1.12, semanticcache 1.4.11→1.4.12, telemetry 1.4.12→1.4.13, transports 1.4.0→1.4.1. Changelog entries document Bedrock streaming structured output fix and test validations.

Sequence Diagram

sequenceDiagram
    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
Loading

Estimated Code Review Effort

🎯 4 (Complex) | ⏱️ ~50 minutes

Possibly Related PRs

Suggested Reviewers

  • danpiths
  • Pratham-Mishra04

🐰 Structured output flows like streams so clear,
No tool calls hiding—just content we hear!
Bedrock now sings in harmony true,
With finish reasons that know what to do. 🌿✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title 'fixes structured output for bedrock' clearly and concisely summarizes the main change: adding structured output support to the Bedrock provider.
Description check ✅ Passed The PR description comprehensively covers all key template sections including summary, detailed changes, type of change, affected areas, testing instructions, breaking changes, and relevant checklist items.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch 01-19-fixes_structured_output_for_bedrock

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

@github-actions
Copy link
Contributor

🧪 Test Suite Available

This PR can be tested by a repository admin.

Run tests for PR #1372

@akshaydeo akshaydeo marked this pull request as ready for review January 19, 2026 05:00
Copy link
Contributor Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

@akshaydeo akshaydeo force-pushed the 01-19-fixes_structured_output_for_bedrock branch from 2353e0d to 52d3053 Compare January 19, 2026 05:17
Copy link
Contributor

@coderabbitai coderabbitai bot left a 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.
Only Choices[0] gets the structured-output override today; if n > 1, other choices can still surface tool_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.
isAccumulatingStructuredOutput is never reset. If Bedrock can emit multiple tool_use blocks 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.

@akshaydeo akshaydeo merged commit d224cb9 into main Jan 19, 2026
9 checks passed
@akshaydeo akshaydeo deleted the 01-19-fixes_structured_output_for_bedrock branch January 19, 2026 06:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants