Text Generation
Structured Output
Constrain the reply to JSON that matches a schema
Structured Output
Structured output constrains a model to return JSON that matches a schema instead of free-form prose. Use it when the reply drives game logic — extracting fields, classifying, or producing data your code consumes directly, with no parsing guesswork.
Structured output is available only on structured-output-capable models.
Providing a schema
Describe the shape you want with a JSON schema:
{
"schema": {
"type": "object",
"properties": {
"intent": { "type": "string" },
"targetNpc": { "type": "string" },
"urgency": { "type": "number" }
},
"required": ["intent"]
},
"schemaName": "PlayerIntent",
"schemaDescription": "Structured interpretation of a player's message"
}The reply is then valid JSON conforming to that schema.
Fixed choice sets
When you only need the model to pick from a fixed set of values, provide an enum instead of a full schema:
{ "enum": ["attack", "defend", "flee", "negotiate"] }When to use it
- Extract structured fields from free text (names, dates, quantities).
- Classify a message into a category or intent.
- Drive logic — feed the JSON straight into game systems without brittle string parsing.
For the exact call in your language, see the JavaScript, Unity, or Unreal text generation guide.