How to get structured JSON responses from agent tasks using JSON Schema
The Problem
You want the agent to return structured data (not free-form text) so your application can parse and act on the result programmatically.
Solution: JSON Schema
Pass a JSON schema to the agent via Spring properties or the fluent API. The agent constrains its output to match the schema.
Via Spring Properties
agent-client: claude: json-schema: type: object properties: summary: type: string description: "A brief summary of what was done" files_changed: type: array items: type: string description: "List of files that were created or modified" success: type: boolean required: - summary - success
Via the Fluent API
AgentClient agentClient = agentClientBuilder.build();AgentClientResponse response = agentClient.goal("Analyze the project structure") .workingDirectory(projectDir) .run();// Parse the structured responseString result = response.getResult();JsonNode json = objectMapper.readTree(result);String summary = json.get("summary").asText();
Provider support varies. JSON schema structured output is currently supported by the Claude provider. Codex and Gemini may return free-form text even when a schema is configured. Check the provider-specific reference pages for current support.
{"docsConfig":{"$schema":"https://mintlify.com/docs.json","theme":"mint","name":"Spring AI Community","colors":{"primary":"#4A90E2","light":"#5BA3F5","dark":"#3A7BC8"},"favicon":"https://mintcdn.com/springaicommunity/IurpyCTD3r0wVRLR/logo/favicon.svg?fit=max\u0026auto=format\u0026n=IurpyCTD3r0wVRLR\u0026q=85\u0026s=9a684f834b1387a6cb833c4181af928e","logo":"https://mintcdn.com/springaicommunity/IurpyCTD3r0wVRLR/logo/universal.svg?fit=max\u0026auto=format\u0026n=IurpyCTD3r0wVRLR\u0026q=85\u0026s=dc08cc7f12f669d12519624ebb0503ce","navbar":{"primary":{"type":"button","label":"Propose Project","href":"https://github.com/spring-ai-community/community/issues/new?template=application.yml"}},"footer":{"socials":{"github":"https://github.com/spring-ai-community","x":"https://x.com/springcentral"}},"integrations":{"plausible":{"domain":"springaicommunity.mintlify.app"}},"styling":{"latex":true},"navigation":{"pages":[]}},"deployment":{"deploymentMetadataValue":{"subdomain":"springaicommunity","hasAudioNarration":false,"actualSubdomain":"springaicommunity","customDomains":[],"gitSource":{"type":"github","owner":"markpollack","repo":"mintlify-docs","deployBranch":"main","contentDirectory":"","isPrivate":false,"mountPath":"","label":""},"entitlements":{},"buildId":"6aecd325d49e4c427f5c4a33:failure","clientVersion":"0.0.4277","searchFilterCounts":[{"language":"default","tag":"Documentation","count":72},{"language":"default","tag":"Blog","count":47},{"language":"default","tag":"Projects","count":19},{"language":"default","tag":"Archive","count":9},{"language":"default","tag":"Agents","count":9},{"language":"default","tag":"Community","count":8},{"language":"default","tag":"Active Projects","count":8},{"language":"default","tag":"Moved to markpollack","count":7},{"language":"default","tag":"Getting Started","count":7},{"language":"default","tag":"MCP","count":7}]},"assistantConfig":{},"basePath":"","hasChatPermissions":false,"hasWebMcpPermissions":false,"toggles":[{"name":"kill-isr","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"custom-rbac-roles","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"agent-mintlify-slack","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"agent-integrations-settings","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"rbac-expansion","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"automations-pr-grouping","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"custom-prefix","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"analytics-v7","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"user-flows-analytics","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"no-publish-flow","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workos-onboarding","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"snapshot-serving-live","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"stripTemperatureMiddleware","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"support-platform-pylon-zendesk","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"snapshot-serving","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"instant-rollback","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"granular-notifications-server","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"granular-notifications","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"automations-fable","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"fixed-ai-action-pricing","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"site-roles","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"automation-resolve-merge-conflict","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"scoped-publishing","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"mintql","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"page-level-analytics","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"editor-version-history-v2","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"billing-page-v2","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"full-page-search","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workspace-projects","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"assistant-v5","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"fork-pr-previews","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"revalidation-jwt","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workos-sso-scim","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"hobby-abuse-scan","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"dashboard-inbox","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workos-signup","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"turbopuffer-dual-write","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workos-enabled","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"approve-review-flow","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"editor-metadata","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"sso-setup-deadline-banner","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"turbopuffer-serve","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"live-agents","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"starter-pricing","enabled":true,"variant":{"name":"control","enabled":true,"payload":{"type":"string","value":"control"},"feature_enabled":true},"impressionData":false},{"name":"llms-txt-v2","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"wildcard-email-auth","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false}],"googleFontsInlined":false},"customCss":[]}
{"page":{"pagePath":"agent-client/howto/structured-output","slug":"/agent-client/howto/structured-output","pageMetadata":{"title":"Structured Output","description":"How to get structured JSON responses from agent tasks using JSON Schema","sidebarTitle":"Structured Output","href":"/agent-client/howto/structured-output"},"description":{"compiledSource":"\"use strict\";\nconst {jsx: _jsx} = arguments[0];\nconst {useMDXComponents: _provideComponents} = arguments[0];\nfunction _createMdxContent(props) {\n const _components = {\n p: \"p\",\n ..._provideComponents(),\n ...props.components\n };\n return _jsx(_components.p, {\n children: \"How to get structured JSON responses from agent tasks using JSON Schema\"\n });\n}\nfunction MDXContent(props = {}) {\n const {wrapper: MDXLayout} = {\n ..._provideComponents(),\n ...props.components\n };\n return MDXLayout ? _jsx(MDXLayout, {\n ...props,\n children: _jsx(_createMdxContent, {\n ...props\n })\n }) : _createMdxContent(props);\n}\nreturn {\n default: MDXContent\n};\n","frontmatter":{},"scope":{}},"pageType":"default","mdx":{"mdxSource":{"compiledSource":"\"use strict\";const{Fragment:_Fragment,jsx:_jsx,jsxs:_jsxs}=arguments[0];const{useMDXComponents:_provideComponents}=arguments[0];function _createMdxContent(props){const _components={a:`a`,code:`code`,p:`p`,pre:`pre`,span:`span`,strong:`strong`,tbody:`tbody`,td:`td`,th:`th`,thead:`thead`,tr:`tr`,..._provideComponents(),...props.components},{CodeBlock,Heading,Table,Warning}=_components;if(!CodeBlock)_missingMdxReference(`CodeBlock`,true);if(!Heading)_missingMdxReference(`Heading`,true);if(!Table)_missingMdxReference(`Table`,true);if(!Warning)_missingMdxReference(`Warning`,true);return _jsxs(_Fragment,{children:[_jsx(Heading,{level:`2`,id:`the-problem`,children:`The Problem`}),`\n`,_jsx(_components.p,{children:`You want the agent to return structured data (not free-form text) so your application can parse and act on the result programmatically.`}),`\n`,_jsx(Heading,{level:`2`,id:`solution-json-schema`,children:`Solution: JSON Schema`}),`\n`,_jsx(_components.p,{children:`Pass a JSON schema to the agent via Spring properties or the fluent API. The agent constrains its output to match the schema.`}),`\n`,_jsx(Heading,{level:`3`,id:`via-spring-properties`,children:`Via Spring Properties`}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`18`,language:`yaml`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`yaml`,children:_jsxs(_components.code,{language:`yaml`,numberOfLines:`18`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#116329`,\"--shiki-dark\":`#569CD6`},children:`agent-client`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`:`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#116329`,\"--shiki-dark\":`#569CD6`},children:` claude`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`:`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#116329`,\"--shiki-dark\":`#569CD6`},children:` json-schema`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`:`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#116329`,\"--shiki-dark\":`#569CD6`},children:` type`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`object`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#116329`,\"--shiki-dark\":`#569CD6`},children:` properties`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`:`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#116329`,\"--shiki-dark\":`#569CD6`},children:` summary`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`:`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#116329`,\"--shiki-dark\":`#569CD6`},children:` type`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`string`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#116329`,\"--shiki-dark\":`#569CD6`},children:` description`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"A brief summary of what was done\"`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#116329`,\"--shiki-dark\":`#569CD6`},children:` files_changed`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`:`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#116329`,\"--shiki-dark\":`#569CD6`},children:` type`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`array`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#116329`,\"--shiki-dark\":`#569CD6`},children:` items`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`:`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#116329`,\"--shiki-dark\":`#569CD6`},children:` type`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`string`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#116329`,\"--shiki-dark\":`#569CD6`},children:` description`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"List of files that were created or modified\"`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#116329`,\"--shiki-dark\":`#569CD6`},children:` success`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`:`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#116329`,\"--shiki-dark\":`#569CD6`},children:` type`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`boolean`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#116329`,\"--shiki-dark\":`#569CD6`},children:` required`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`:`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` - `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`summary`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` - `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`success`})]}),`\n`]})})}),`\n`,_jsx(Heading,{level:`3`,id:`via-the-fluent-api`,children:`Via the Fluent API`}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`10`,language:`java`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`java`,children:_jsxs(_components.code,{language:`java`,numberOfLines:`10`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#4EC9B0`},children:`AgentClient`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` agentClient`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` agentClientBuilder`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`build`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`();`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#4EC9B0`},children:`AgentClientResponse`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` response`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` agentClient`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`goal`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"Analyze the project structure\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` .`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`workingDirectory`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(projectDir)`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` .`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`run`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`();`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`// Parse the structured response`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#4EC9B0`},children:`String`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` result`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` response`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`getResult`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`();`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#4EC9B0`},children:`JsonNode`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` json`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` objectMapper`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`readTree`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(result);`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#4EC9B0`},children:`String`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` summary`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` json`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`get`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"summary\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`).`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`asText`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`();`})]}),`\n`]})})}),`\n`,_jsx(Warning,{children:_jsxs(_components.p,{children:[_jsx(_components.strong,{children:`Provider support varies.`}),` JSON schema structured output is currently supported by the `,_jsx(_components.strong,{children:`Claude`}),` provider. Codex and Gemini may return free-form text even when a schema is configured. Check the provider-specific reference pages for current support.`]})}),`\n`,_jsx(Heading,{level:`2`,id:`provider-specific-details`,children:`Provider-Specific Details`}),`\n`,_jsxs(Table,{children:[_jsx(_components.thead,{children:_jsxs(_components.tr,{children:[_jsx(_components.th,{children:`Provider`}),_jsx(_components.th,{children:`Structured Output`}),_jsx(_components.th,{children:`Configuration`})]})}),_jsxs(_components.tbody,{children:[_jsxs(_components.tr,{children:[_jsx(_components.td,{children:`Claude`}),_jsxs(_components.td,{children:[`JSON Schema via `,_jsx(_components.code,{children:`json-schema`}),` property`]}),_jsx(_components.td,{children:_jsx(_components.a,{href:`/agent-client/reference/claude-reference#structured-output`,children:`Claude Reference`})})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:`Codex`}),_jsx(_components.td,{children:`Not currently supported`}),_jsx(_components.td,{children:`—`})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:`Gemini`}),_jsx(_components.td,{children:`Not currently supported`}),_jsx(_components.td,{children:`—`})]})]})]})]})}function MDXContent(props={}){const{wrapper:MDXLayout}={..._provideComponents(),...props.components};return MDXLayout?_jsx(MDXLayout,{...props,children:_jsx(_createMdxContent,{...props})}):_createMdxContent(props)}return{default:MDXContent};function _missingMdxReference(id,component){throw new Error(`Expected `+(component?`component`:`object`)+\" `\"+id+\"` to be defined: you likely forgot to import, pass, or provide it.\")}","frontmatter":{},"scope":{"config":{},"pageMetadata":{"title":"Structured Output","description":"How to get structured JSON responses from agent tasks using JSON Schema","sidebarTitle":"Structured Output","href":"/agent-client/howto/structured-output"}}},"mdxSourceWithNoJs":null},"mdxExtracts":{"tableOfContents":[{"title":"The Problem","slug":"the-problem","depth":2,"children":[]},{"title":"Solution: JSON Schema","slug":"solution-json-schema","depth":2,"children":[{"title":"Via Spring Properties","slug":"via-spring-properties","depth":3,"children":[]},{"title":"Via the Fluent API","slug":"via-the-fluent-api","depth":3,"children":[]}]},{"title":"Provider-Specific Details","slug":"provider-specific-details","depth":2,"children":[]}],"codeExamples":{}},"jsLinks":["/_mintlify/custom/springaicommunity/d8136ef5deaa173a/gsap-loader.js"],"subdomain":"springaicommunity","siteName":"Spring AI Community","title":"Structured Output - Spring AI Community","navMaps":{"firstHrefInVersion":{},"firstHrefInLanguage":{}},"lastModified":"2026-04-30T02:53:53.627Z","originalFileLocation":"agent-client/howto/structured-output.mdx"},"headHtml":"\u003cscript data-mint-head>(function(){var d=document.documentElement,p=null;if(!p){try{p=localStorage.getItem(\"isDarkMode\")}catch(e){}if(p==='true')p='dark';else if(p==='false')p='light';if(p!=='light'\u0026\u0026p!=='dark'\u0026\u0026p!=='system')p=\"system\"}var r=p==='system'?(matchMedia(\"(prefers-color-scheme: dark)\").matches?'dark':'light'):p;d.classList.remove(r==='dark'?'light':'dark');d.classList.add(r);d.setAttribute(\"data-theme-preference\",p)})();\u003c/script>\u003cmeta data-mint-head name=\"description\" content=\"How to get structured JSON responses from agent tasks using JSON Schema\">\u003cmeta data-mint-head name=\"application-name\" content=\"Spring AI Community\">\u003cmeta data-mint-head name=\"generator\" content=\"Mintlify\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"192x192\" href=\"/mintlify-assets/_mintlify/favicons/springaicommunity/R5tSWKqei29rcfGA/_generated/favicon/android-chrome-192x192.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"apple-touch-icon\" type=\"image/png\" sizes=\"180x180\" href=\"/mintlify-assets/_mintlify/favicons/springaicommunity/R5tSWKqei29rcfGA/_generated/favicon/apple-touch-icon.png\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"16x16\" href=\"/mintlify-assets/_mintlify/favicons/springaicommunity/R5tSWKqei29rcfGA/_generated/favicon/favicon-16x16.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"32x32\" href=\"/mintlify-assets/_mintlify/favicons/springaicommunity/R5tSWKqei29rcfGA/_generated/favicon/favicon-32x32.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"shortcut icon\" type=\"image/x-icon\" href=\"/mintlify-assets/_mintlify/favicons/springaicommunity/R5tSWKqei29rcfGA/_generated/favicon/favicon.ico\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"192x192\" href=\"/mintlify-assets/_mintlify/favicons/springaicommunity/R5tSWKqei29rcfGA/_generated/favicon-dark/android-chrome-192x192.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"16x16\" href=\"/mintlify-assets/_mintlify/favicons/springaicommunity/R5tSWKqei29rcfGA/_generated/favicon-dark/favicon-16x16.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"32x32\" href=\"/mintlify-assets/_mintlify/favicons/springaicommunity/R5tSWKqei29rcfGA/_generated/favicon-dark/favicon-32x32.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"shortcut icon\" type=\"image/x-icon\" href=\"/mintlify-assets/_mintlify/favicons/springaicommunity/R5tSWKqei29rcfGA/_generated/favicon-dark/favicon.ico\" media=\"(prefers-color-scheme: dark)\">\u003cmeta data-mint-head property=\"og:title\" content=\"Structured Output - Spring AI Community\">\u003cmeta data-mint-head property=\"og:description\" content=\"How to get structured JSON responses from agent tasks using JSON Schema\">\u003cmeta data-mint-head property=\"og:site_name\" content=\"Spring AI Community\">\u003cmeta data-mint-head property=\"og:url\" content=\"https://springaicommunity.mintlify.app/agent-client/howto/structured-output\">\u003cmeta data-mint-head property=\"og:type\" content=\"website\">\u003cmeta data-mint-head property=\"og:image\" content=\"https://springaicommunity.mintlify.site/_mintlify/api/og/v2?division=Documentation\u0026amp;title=Structured+Output\u0026amp;description=How+to+get+structured+JSON+responses+from+agent+tasks+using+JSON+Schema\u0026amp;theme=f4a505157a245569a37a69ad\u0026amp;signature=cea665352fcc4de75a3dc67de50c00f3ddab956dbcc6677b43cf499185635518\">\u003cmeta data-mint-head property=\"og:image:width\" content=\"1200\">\u003cmeta data-mint-head property=\"og:image:height\" content=\"630\">\u003cmeta data-mint-head name=\"twitter:card\" content=\"summary_large_image\">\u003cmeta data-mint-head name=\"twitter:title\" content=\"Structured Output - Spring AI Community\">\u003cmeta data-mint-head name=\"twitter:description\" content=\"How to get structured JSON responses from agent tasks using JSON Schema\">\u003cmeta data-mint-head name=\"twitter:image\" content=\"https://springaicommunity.mintlify.site/_mintlify/api/og/v2?division=Documentation\u0026amp;title=Structured+Output\u0026amp;description=How+to+get+structured+JSON+responses+from+agent+tasks+using+JSON+Schema\u0026amp;theme=f4a505157a245569a37a69ad\u0026amp;signature=cea665352fcc4de75a3dc67de50c00f3ddab956dbcc6677b43cf499185635518\">\u003cmeta data-mint-head name=\"twitter:image:width\" content=\"1200\">\u003cmeta data-mint-head name=\"twitter:image:height\" content=\"630\">\u003cmeta data-mint-head name=\"msapplication-config\" content=\"/mintlify-assets/_mintlify/favicons/springaicommunity/R5tSWKqei29rcfGA/_generated/favicon/browserconfig.xml\">\u003cmeta data-mint-head name=\"apple-mobile-web-app-title\" content=\"Spring AI Community\">\u003cmeta data-mint-head name=\"msapplication-TileColor\" content=\"#4A90E2\">\u003clink data-mint-head rel=\"canonical\" href=\"https://springaicommunity.mintlify.app/agent-client/howto/structured-output\">\u003clink data-mint-head rel=\"alternate\" type=\"application/xml\" href=\"/sitemap.xml\">\u003clink data-mint-head rel=\"alternate\" type=\"text/markdown\" href=\"/agent-client/howto/structured-output.md\">\u003cscript data-mint-head type=\"application/ld+json\">{\"@context\":\"https://schema.org\",\"@type\":\"WebSite\",\"name\":\"Spring AI Community\",\"publisher\":{\"@type\":\"Organization\",\"name\":\"Spring AI Community\"},\"provider\":{\"@type\":\"Organization\",\"name\":\"Mintlify\",\"url\":\"https://mintlify.com\"}}\u003c/script>","agentPointerHref":"/agent-client/howto/structured-output.md","siteName":"Spring AI Community","nav":{"global":null,"anchors":[{"anchor":"Documentation","icon":"book-open","groups":[{"group":"Community","pages":[{"title":"Spring AI Community","href":"/community"},{"title":"Governance","href":"/community/governance"},{"title":"Contributors","href":"/community/contributors"},{"title":"Project Creation Guide","href":"/community/project-guide"},{"title":"Release Management","href":"/community/releases"},{"title":"Project Lead Guide","href":"/community/project-lead-guide"},{"title":"Spring AI Integration","href":"/community/integration"}]},{"group":"Projects","pages":[{"title":"Our Projects","href":"/projects/index"},{"title":"Spring AI Bedrock AgentCore","href":"/projects/incubating/spring-ai-bedrock-agentcore"},{"group":"Active Projects","pages":[{"title":"Spring AI Agent Utils","href":"/projects/incubating/spring-ai-agent-utils"},{"title":"Spring AI Tool Search Tool","href":"/projects/incubating/spring-ai-tool-search-tool"},{"title":"MCP Annotations","href":"/projects/incubating/mcp-annotations"},{"title":"MCP Security","href":"/projects/incubating/mcp-security"},{"title":"Spring AI Replicate","href":"/projects/incubating/spring-ai-replicate"},{"title":"Spring AI Playground","href":"/projects/incubating/spring-ai-playground"},{"title":"Spring AG-UI","href":"/projects/incubating/spring-agui"},{"title":"Spring AI Vaadin","href":"/projects/incubating/spring-ai-vaadin"}]},{"group":"Archive","pages":[{"group":"Moved to markpollack","pages":[{"title":"GitHub Collector","href":"/projects/incubating/github-collector"},{"title":"ACP Java SDK","sidebarTitle":"Overview","href":"/acp-java-sdk/index"},{"title":"Agent Client","href":"/projects/incubating/agent-client"},{"title":"Agent Judge","href":"/projects/incubating/agent-judge"},{"title":"Agent Sandbox","href":"/projects/incubating/agent-sandbox"},{"title":"Agent Bench","href":"/projects/incubating/agent-bench"},{"title":"Claude Agent SDK for Java","sidebarTitle":"Overview","href":"/claude-agent-sdk/index"}]},{"group":"Retired","pages":[{"title":"Moonshot","href":"/projects/attic/moonshot"},{"title":"QianFan","href":"/projects/attic/qianfan"}]}]}]},{"group":"Get Involved","pages":[{"title":"Get Involved","href":"/get-involved/index"}]},{"group":"Blog","pages":[{"group":"Agents","pages":[{"title":"Building Effective Agents with Spring AI (Part 1)","sidebarTitle":"Building Effective Agents with...","href":"/blog/agents/agentic-patterns-1"},{"title":"Spring AI Agentic Patterns (Part 1): Agent Skills - Modular, Reusable Capabilities","sidebarTitle":"Agentic Patterns (Part 1): Agent...","href":"/blog/agents/agent-skills"},{"title":"Spring AI Agentic Patterns (Part 2): AskUserQuestionTool - Agents That Clarify Before Acting","sidebarTitle":"Agentic Patterns (Part 2):...","href":"/blog/agents/ask-user-question-tool"},{"title":"Spring AI Agentic Patterns (Part 3): Why Your AI Agent Forgets Tasks (And How to Fix It)","sidebarTitle":"Agentic Patterns (Part 3): Why Your...","href":"/blog/agents/todowrite"},{"title":"Spring AI Agentic Patterns (Part 4): Subagent Orchestration","sidebarTitle":"Agentic Patterns (Part 4): Subagent...","href":"/blog/agents/task-subagents"},{"title":"Anthropic Agent Skills Support in Spring AI","sidebarTitle":"Anthropic Agent Skills Support in...","href":"/blog/agents/anthropic-agentic-skills"},{"title":"Introducing Spring AI Agents and Spring AI Bench","sidebarTitle":"Introducing Spring AI Agents and...","href":"/blog/agents/agents-and-benchmarks"},{"title":"Create Self-Improving AI Agents Using Spring AI Recursive Advisors","sidebarTitle":"Create Self-Improving AI Agents...","href":"/blog/agents/recursive-advisors"},{"title":"LLM Response Evaluation with Spring AI: Building LLM-as-a-Judge Using Recursive Advisors","sidebarTitle":"LLM Response Evaluation with Spring...","href":"/blog/agents/llm-as-judge"}]},{"group":"MCP","pages":[{"title":"Announcing Spring AI MCP: A Java SDK for the Model Context Protocol","sidebarTitle":"Announcing Spring AI MCP: A Java...","href":"/blog/mcp/mcp-announcement"},{"title":"Introducing the Model Context Protocol Java SDK","sidebarTitle":"Introducing the Model Context...","href":"/blog/mcp/mcp-java-sdk-released"},{"title":"Connect Your AI to Everything: Spring AI's MCP Boot Starters","sidebarTitle":"Connect Your AI to Everything:...","href":"/blog/mcp/mcp-intro"},{"title":"Dynamic Tool Updates in Spring AI's Model Context Protocol","sidebarTitle":"Dynamic Tool Updates in Spring AI's...","href":"/blog/mcp/mcp-dynamic-tool-updates"},{"title":"Securing MCP Servers with Spring AI","sidebarTitle":"Securing MCP Servers with Spring AI","href":"/blog/mcp/mcp-server-security"},{"title":"Securing Spring AI MCP servers with OAuth2","sidebarTitle":"Securing Spring AI MCP servers with...","href":"/blog/mcp/mcp-server-oauth2"},{"title":"MCP Authorization in practice with Spring AI and OAuth2","sidebarTitle":"MCP Authorization in practice with...","href":"/blog/mcp/mcp-client-oauth2"}]},{"group":"Tools \u0026 Structured Output","pages":[{"title":"Function Calling in Java and Spring AI using the latest Mistral AI API","sidebarTitle":"Function Calling in Java and Spring...","href":"/blog/tools/function-calling-mistral"},{"title":"Spring AI with Ollama Tool Support","sidebarTitle":"with Ollama Tool Support","href":"/blog/tools/ollama-tool-support"},{"title":"Spring AI - Structured Output","sidebarTitle":"- Structured Output","href":"/blog/tools/structured-output"},{"title":"Spring AI Embraces OpenAI's Structured Outputs: Enhancing JSON Response Reliability","sidebarTitle":"Embraces OpenAI's Structured...","href":"/blog/tools/openai-structured-outputs"},{"title":"Beyond JSON: Converting Spring AI Tool Response Formats to TOON, XML, CSV, YAML, ...","sidebarTitle":"Beyond JSON: Converting Spring AI...","href":"/blog/tools/tool-response-formats"},{"title":"Smart Tool Selection: Achieving 34-64% Token Savings with Spring AI's Dynamic Tool Discovery","sidebarTitle":"Smart Tool Selection: Achieving...","href":"/blog/tools/tool-search"},{"title":"Explainable AI Agents: Capture LLM Tool Call Reasoning with Spring AI","sidebarTitle":"Explainable AI Agents: Capture LLM...","href":"/blog/tools/tool-argument-augmenter"}]},{"group":"Model Providers","pages":[{"title":"Spring AI with Groq - a blazingly fast AI inference engine","sidebarTitle":"with Groq - a blazingly fast AI...","href":"/blog/model-providers/groq"},{"title":"Spring AI with NVIDIA LLM API","sidebarTitle":"with NVIDIA LLM API","href":"/blog/model-providers/nvidia"},{"title":"Leverage the Power of 45k, free, Hugging Face Models with Spring AI and Ollama","sidebarTitle":"Leverage the Power of 45k, free,...","href":"/blog/model-providers/ollama-huggingface"},{"title":"Introducing Spring AI Amazon Bedrock Nova Integration via Converse API","sidebarTitle":"Introducing Spring AI Amazon...","href":"/blog/model-providers/bedrock-nova"},{"title":"Spring AI with Docker Model Runner","sidebarTitle":"with Docker Model Runner","href":"/blog/model-providers/docker-model-runner"},{"title":"Prompt Caching Support in Spring AI with Anthropic Claude","sidebarTitle":"Prompt Caching Support in Spring AI...","href":"/blog/model-providers/anthropic-prompt-caching"},{"title":"AWS Bedrock Prompt Caching Support in Spring AI","sidebarTitle":"AWS Bedrock Prompt Caching Support...","href":"/blog/model-providers/bedrock-prompt-caching"}]},{"group":"Prompts \u0026 Output","pages":[{"title":"Prompt Engineering Techniques with Spring AI","sidebarTitle":"Prompt Engineering Techniques with...","href":"/blog/prompts-and-output/prompt-engineering-patterns"},{"title":"Spring AI - Multimodality - Orbis Sensualium Pictus","sidebarTitle":"- Multimodality - Orbis Sensualium...","href":"/blog/prompts-and-output/multimodality"},{"title":"Audio Multimodality: Expanding AI Interaction with Spring AI and OpenAI","sidebarTitle":"Audio Multimodality: Expanding AI...","href":"/blog/prompts-and-output/audio-modality"},{"title":"Repository Vector Search Methods","sidebarTitle":"Repository Vector Search Methods","href":"/blog/prompts-and-output/vector-search-methods"}]},{"group":"Getting Started","pages":[{"title":"Why Spring AI: The Seamless Path to Generative AI","sidebarTitle":"Why Spring AI: The Seamless Path to...","href":"/blog/getting-started/why-spring-ai"},{"title":"Your First Spring AI 1.0 Application","sidebarTitle":"Your First Spring AI 1.0...","href":"/blog/getting-started/your-first-spring-ai-1.0-application"},{"title":"Spring Tips: Spring AI ","sidebarTitle":"Spring AI","href":"/blog/getting-started/spring-tips-spring-ai"},{"title":"Spring Tips: Spring AI Redux","sidebarTitle":"Spring AI Redux","href":"/blog/getting-started/spring-tips-spring-ai-redux"},{"title":"Spring Tips: Vector Databases with Spring AI","sidebarTitle":"Vector Databases with Spring AI","href":"/blog/getting-started/spring-tips-vector-databases"},{"title":"Using Spring AI 1.0.0-SNAPSHOT: Important Changes and Updates","sidebarTitle":"Using Spring AI 1.0.0-SNAPSHOT:...","href":"/blog/getting-started/update-to-snapshots"},{"title":"Using Spring AI 1.0.0-SNAPSHOT: Part 2 - Important Changes and Updates","sidebarTitle":"Using Spring AI 1.0.0-SNAPSHOT:...","href":"/blog/getting-started/using-snapshots-part-2"}]},{"group":"Advisors \u0026 RAG","pages":[{"title":"Supercharging Your AI Applications with Spring AI Advisors","sidebarTitle":"Supercharging Your AI Applications...","href":"/blog/advisors/spring-ai-advisors"},{"title":"AI Meets Spring Petclinic: Implementing an AI Assistant with Spring AI (Part I)","sidebarTitle":"Petclinic: Implementing an AI...","href":"/blog/advisors/petclinic-part-1"},{"title":"AI Meets Spring Petclinic: Implementing an AI Assistant with Spring AI (Part II)","sidebarTitle":"Petclinic: Implementing an AI...","href":"/blog/advisors/petclinic-part-2"}]},{"group":"Community","pages":[{"title":"Introducing the Spring AI Community GitHub Organization","sidebarTitle":"Introducing the Spring AI Community...","href":"/blog/community/community-announcement"}]}]}]},{"anchor":"Blog","icon":"newspaper","groups":[{"group":"Blog","pages":[{"title":"Blog","sidebarTitle":"Blog","href":"/blog"}]}]},{"anchor":"GitHub","href":"https://github.com/spring-ai-community","icon":"github"}]},"basePath":"","title":"Structured Output - Spring AI Community","deploymentId":"dpl_BzgRxZmUbhHRoPLkBx1DiVRSyQhV","buildId":"dpl_BzgRxZmUbhHRoPLkBx1DiVRSyQhV","dynamics":[],"chunks":[]}