0Pricing
AI Prompt Engineering · Lesson

JSON Schema in Prompts

Constraining output shape.

Schema as the Output Contract

A JSON Schema declaratively describes the shape of valid output: types, required keys, value constraints, and nesting. When passed to a structured-output API it becomes a hard contract; when embedded in a prompt it becomes strong guidance.

Mastering schema authoring is the core skill of structured generation.

The strict Flag Changes Everything

In strict mode, providers require that every property is listed in required and that additionalProperties is false. Optional fields are expressed as a union with null, not by omission.

{
  'type': 'object',
  'properties': {
    'name': {'type': 'string'},
    'nickname': {'type': ['string', 'null']}
  },
  'required': ['name', 'nickname'],
  'additionalProperties': False
}

All lessons in this course

  1. Why Structured Output
  2. JSON Schema in Prompts
  3. Tool/Function Schemas
  4. Repair and Validation Loops
← Back to AI Prompt Engineering