Open History to see the last commit
1import type { ToolConfiguration } from '@aws-sdk/client-bedrock-runtime'
2import type { DocumentType } from '@smithy/types'
3
4export const STRUCTURED_TOOL_NAME = 'structured_output'
5
6/**
7 * Converse has no native json_schema response_format. Structured output is
8 * achieved by forcing a single tool whose input schema is the requested output
9 * schema; the model's tool-use `input` is the structured result.
10 */
11export function buildStructuredToolConfig(schema: unknown): ToolConfiguration {
12 return {
13 tools: [
14 {
15 toolSpec: {
16 name: STRUCTURED_TOOL_NAME,
17 description: 'Return the final answer as structured JSON.',
18 inputSchema: { json: schema as DocumentType },
19 },
20 },
21 ],
22 toolChoice: { tool: { name: STRUCTURED_TOOL_NAME } },
23 }
24}