Repository navigation
Bedrock Build-in JSON mode #959
Replies: 1 comment
|
Thanks for writing this up back in the M1 days, and for pointing at the exact docs section so the gap between the OpenAI/Azure JSON mode and Bedrock was easy to see. Short version: at the time this was an upstream limitation rather than a Spring AI one. Neither the Anthropic Messages API nor Bedrock had a JSON mode, so
Run on 2.0.1 against Code usedrecord ActorsFilms(String actor, List<String> movies) {}
BedrockProxyChatModel model = BedrockProxyChatModel.builder()
.bedrockRuntimeClient(client) // plain BedrockRuntimeClient, us-east-1
.options(BedrockChatOptions.builder()
.model("us.anthropic.claude-haiku-4-5-20251001-v1:0")
.maxTokens(300)
.build())
.build();
// 1) ChatClient path
ActorsFilms af = ChatClient.create(model).prompt()
.advisors(AdvisorParams.ENABLE_NATIVE_STRUCTURED_OUTPUT)
.user("Give me a real actor and three of their movies.")
.call()
.entity(ActorsFilms.class);
// 2) explicit schema
String schema = """
{"type":"object","properties":{"actor":{"type":"string"},
"movies":{"type":"array","items":{"type":"string"}}},
"required":["actor","movies"],"additionalProperties":false}""";
ChatResponse resp = model.call(new Prompt("Give me a real actor and three of their movies.",
BedrockChatOptions.builder()
.model("us.anthropic.claude-haiku-4-5-20251001-v1:0")
.outputSchema(schema)
.build()));One caveat: AWS gates |
Uh oh!
There was an error while loading. Please reload this page.
Hi everyone,
Is the inability to configure Bedrock (Anthropic3ChatOptions) to generate JSON output a Bedrock limitation? It would be helpful if we could configure it like it is in Azure or OpenAI:
https://docs.spring.io/spring-ai/reference/api/structured-output-converter.html#_build_in_json_mode
All reactions