Course contentsShow
← AI Engineering
Lesson 759 of 1,88619. Structured Output and ValidationFree lesson

Schema Definition in Prompts

Master techniques for describing desired JSON schemas clearly within your prompts.

Schema Definition in Prompts

What you'll learn: How to describe your desired JSON structure directly in prompts to guide the LLM toward producing exactly the output format you need.

Why Describe Schemas in Prompts?

In the previous lesson, you learned that JSON mode produces valid JSON—but without a schema, the model might invent any structure it thinks fits. To get predictable JSON with specific fields, types, and nesting, you need to tell the model what structure you want.

Think of it like ordering a custom sandwich: "JSON mode" tells the chef to make you a sandwich (valid JSON), but describing the schema is like saying "I want sourdough bread, turkey, swiss cheese, lettuce, and tomato—in that order." You get exactly what you specified.

How to Define Schemas in Prompts

Include a clear description of your desired JSON structure directly in your prompt. Be explicit about:

  • Field names you expect
  • Data types (string, number, boolean, array, object)
  • Required vs optional fields
  • Nested structures if applicable

Example Prompt Structure

Extract user information and return as JSON with this structure:
{
  "name": "string",
  "age": "number",
  "email": "string",
  "interests": ["array of strings"]
}

You can also describe it in prose: "Return JSON with fields: name (string), age (number), email (string), and interests (array of strings)."

The Precision Advantage

By defining the schema in your prompt, you shift from "give me some JSON" to "give me this specific JSON." The model will attempt to match your described structure, making downstream parsing and validation far more reliable.

Key Takeaway: Schema definition in prompts transforms unpredictable JSON output into structured, consistent data by explicitly describing the field names, types, and structure you expect the model to produce.