fix(bedrock): honor response_format on Converse requests
Merged
PC
3d ago+195+195+012345678901234567890123456789-5-5-0123456789
Description
With a Bedrock model, response_format was silently ignored: buildConverseParts never read it, so a json_schema or json_object request came back as free text with a 200. ADR-0011 asks for such a field to be translated or rejected.
Changes, for both Converse and ConverseStream:
json_schemais sent as native structured output (outputConfig.textFormat), with name, description and the schema bytes as received.json_object, andjson_schemawith an absent or empty schema, add a system instruction asking for a JSON object, as the Anthropic adapter does.textandnullleave the request unchanged; malformed values (including a missing or unknowntypeand anullschema) get a 400.- Rows for Bedrock added to the ADR-0011 table.
The schema is not rewritten. If a model does not support structured output, or the schema uses something Bedrock does not accept (for example an object without additionalProperties: false), Bedrock's validation error now reaches the client.
Tests in internal/providers/bedrock/response_format_test.go check the built requests; they were not run against the live Bedrock service. The package tests and go vet pass.
AI Generated (optional)
This change was prepared with AI assistance.
Summary by CodeRabbit
- New Features
- Bedrock supports JSON response formats. Requests with a nonempty JSON Schema use structured output, including any provided name or description. Missing or empty schemas prompt the model to return a JSON object.
- JSON object requests include an instruction to return a single JSON object. These settings apply to both standard and streaming responses.
- Text and null response formats leave requests unchanged.
- Bug Fixes
- Malformed schemas and unsupported response-format settings return request errors.