Structured Outputs
ShuYou provides Structured Outputs to ensure model responses strictly follow the JSON Schema format you define. When you have a fixed requirement for structured data, this feature is exactly what you need. ShuYou supports structured outputs across multiple API protocols:- OpenAI Chat Completion API: via the
response_formatparameter - OpenAI Responses API: via the
text.formatparameter - Anthropic Messages API: via the
output_config.formatparameter (recommended) or tool calling - Google Vertex AI API: via the
responseMimeType+responseSchemaparameters
OpenAI Chat Completion API
Parameter Reference
response_format- Set
\{ "type": "json_object" \}: the output is valid JSON, but a specific structure or set of fields is not guaranteed. - Set
\{ "type": "json_schema", "json_schema": \{...\} \}: stricter control over the JSON output structure, providing stronger type and structural guarantees.
- Use
json_objectmode
content returns valid JSON
- Use
json_schemamode
content will follow the specified schema and provide JSON data:
API Call Examples
Python
TypeScript
OpenAI Responses API
The OpenAI Responses API uses thetext.format parameter to control structured outputs, rather than response_format.
Parameter Reference
text.format- Set
\{ "type": "text" \}: plain text output (default) - Set
\{ "type": "json_object" \}: JSON mode, guarantees the output is valid JSON - Set
\{ "type": "json_schema", "json_schema": \{...\} \}: Structured Outputs, strictly follow the JSON Schema
API Call Examples
Python
TypeScript
cURL
Anthropic Messages API
Anthropic Claude models support two approaches to structured output:- JSON output (recommended): specify a JSON Schema directly via the
output_config.formatparameter - Tool calling: define a tool and force the model to call it to obtain structured data
Option 1: JSON Output (output_config)
This is Anthropic’s recommended approach, using output_config.format to directly control Claude’s response format.
Parameter Reference
output_config.format.type: set to"json_schema"output_config.format.schema: JSON Schema that defines the output structure
Python
TypeScript
cURL
response.content[0].text:
Option 2: Tool Calling (Tool Use)
You can also obtain structured data that conforms to a specified JSON Schema by defining a tool and forcing the model to call it. How it works- Define a tool whose
input_schemadescribes your expected output structure - Set
tool_choiceto\{"type": "tool", "name": "tool-name"\}to force the model to call that tool - Extract the structured data from the returned
tool_usecontent block
Python
TypeScript
cURL
Comparison
| Feature | JSON Output (output_config) | Tool Calling (Tool Use) |
|---|---|---|
| Parameter location | output_config.format | tools + tool_choice |
| Output location | content[0].text | content[x].input (tool_use block) |
| Best for | Getting a structured response directly | Scenarios where tools must be used as well |
| Complexity | Simpler | Requires tool-calling handling |
| Recommendation | ✅ Recommended | Use for specific scenarios |
Google Vertex AI API
Google Vertex AI (Gemini models) implements structured outputs viaresponseMimeType and responseSchema inside config.
Parameter Reference
config.responseMimeTypetext/plain(default): plain text outputapplication/json: JSON output
- JSON Schema that defines the output structure (must be used with
responseMimeType: "application/json")
API Call Examples
Python
TypeScript
Using Enum Types
Vertex AI also supports thetext/x.enum MIME type for classification tasks, where the output will be one of the enum values defined in the schema: