Skip to main content

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_format parameter
  • OpenAI Responses API: via the text.format parameter
  • Anthropic Messages API: via the output_config.format parameter (recommended) or tool calling
  • Google Vertex AI API: via the responseMimeType + responseSchema parameters

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.
  1. Use json_object mode
Request structure:
Response structure: content returns valid JSON
  1. Use json_schema mode
Define the input using the standard JSON Schema format:
The returned content will follow the specified schema and provide JSON data:

API Call Examples

Python
TypeScript

OpenAI Responses API

The OpenAI Responses API uses the text.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:
  1. JSON output (recommended): specify a JSON Schema directly via the output_config.format parameter
  2. 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
Example Output A valid JSON payload is returned in 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
  1. Define a tool whose input_schema describes your expected output structure
  2. Set tool_choice to \{"type": "tool", "name": "tool-name"\} to force the model to call that tool
  3. Extract the structured data from the returned tool_use content block
Python
TypeScript
cURL

Comparison

Google Vertex AI API

Google Vertex AI (Gemini models) implements structured outputs via responseMimeType and responseSchema inside config.

Parameter Reference

config.responseMimeType
  • text/plain (default): plain text output
  • application/json: JSON output
config.responseSchema
  • 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 the text/x.enum MIME type for classification tasks, where the output will be one of the enum values defined in the schema: