Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

JSON Schema

This document explains the JSON schema validation layer exposed by the SDK documentation set.

Goal

The JSON schema flow helps enforce structured model responses when plain free-form text is not enough.

Validation loop

flowchart TD
    PROMPT[Prompt with schema guidance] --> MODEL[LLM response]
    MODEL --> VALIDATE[Schema validation]
    VALIDATE -->|valid| OUTPUT[Accepted output]
    VALIDATE -->|invalid| RETRY[Retry with validation feedback]
    RETRY --> MODEL

What it is useful for

ScenarioWhy schema validation helps
Data extractionEnsures expected keys and types are present
Tool-oriented responsesReduces fragile string parsing
Structured reportsKeeps output machine-readable

Core ideas

  • A schema defines the required shape of the response.
  • Validation checks the model output against that shape.
  • Retry guidance can feed validation errors back into the next model attempt.