C.W.K.
Stream
Lesson 02 of 07 · published

Strict Mode

~22 min · strict, schema-validation

Level 0Tokenizer
0 XP0/54 lessons0/10 achievements
0/120 XP to next level120 XP to go0% complete

Setting strict: true guarantees the model's output matches your JSON Schema exactly. This eliminates the need for output validation — the model is constrained to produce conforming output.

Requirements for Strict Mode

  • additionalProperties must be false on every object in the schema.
  • All fields in properties must be listed in required.
  • Optional fields must use a null type union: "type": ["string", "null"].
  • The model is guaranteed to produce outputs matching the schema.

Strict mode uses constrained decoding at the model level — it's not just validation after the fact. The model literally cannot produce non-conforming output, even for complex nested schemas.

Code

Tool with strict=True·python
{
    "type": "function",
    "name": "create_event",
    "description": "Create a calendar event",
    "parameters": {
        "type": "object",
        "properties": {
            "title": {"type": "string"},
            "date": {"type": "string", "description": "ISO 8601 date"},
            "description": {"type": ["string", "null"]},  # optional via null union
        },
        "required": ["title", "date", "description"],     # ALL fields required
        "additionalProperties": False,                     # mandatory for strict
    },
    "strict": True,
}

External links

Exercise

Take a tool that accepts an enum field. Without strict, prompt the model in a way that tempts an invalid enum value. Watch it return one. Now flip strict=True and watch the API reject the bad call before it reaches you.

Progress

Progress is local-only — sign in to sync across devices.
Spotted a bug or have feedback on this page?Report an Issue

Comments 0

🔔 Reply notifications (sign in)
Sign inPlease sign in to comment.

No comments yet — be the first.