{
  "id": 23014618,
  "title": "Structured output with JSON, validated with Pydantic - Chat Orders",
  "url": "https://urgent.news/2026/12/01/structured-output-with-json-validated-with-pydantic-chat-orders",
  "topic": "tech",
  "section": "Tech",
  "published": "2026-12-01T21:31:27.000Z",
  "source": {
    "name": "Dev.to",
    "slug": "dev-to",
    "url": "https://dev.to/sao2207/structured-output-with-json-validated-with-pydantic-chat-orders-2i4l"
  },
  "original_language": null,
  "account": "Day 3 of the structured output tutorial focuses on using JSON output validated with Pydantic to turn chat orders into a CSV file. The goal is to extract the relevant information from the chat order, such as products, address, payment method, and order status, and format it into a CSV file with one product per row.\n\nPydantic plays a dual role in this process. Firstly, it defines the structure of the expected output, ensuring the model returns the correct fields. Secondly, it validates the output, confirming that every field exists and has the appropriate data type.\n\nThe schema for the Product and Orders classes is provided. The Product class describes a single product with fields for the product name and quantity. The Orders class contains the entire order information, including an address, payment method, and a list of Product objects.\n\nSeveral key points about the schema are worth noting. The description field serves as an instruction for the model, preventing confusion between the customer and product names. The None type allows for optional fields when the message doesn't mention them. Literal restricts the possible values for the payment method, rejecting any inputs that don't match the allowed options. The order field is a boolean indicating whether the message represents an actual order.\n\nThe tutorial emphasizes the importance of setting the temperature to 0 for consistent results, as the same input should always produce the same output. Writing the CSV file is a straightforward Python task using the with open() context manager. The nested models make it easy to flatten the data, looping through the list of Product objects within each order to write one product per row.",
  "summary": "Day Topic Example Status 1 Talking to an LLM from code Classifying emails by category and urgency ✅ Code 2 Roles, examples and delimiters in prompts Translating technical language into plain language ✅ Code 3 Structured output with JSON, validated with Pydantic Turning a chat order into a table 📍 You're here 4 Images with vision models Scanning a receipt and returning a JSON with the products…",
  "summary_source": "publisher",
  "key_points": [
    "Pydantic validates JSON output structure and data types",
    "Product class defines single product fields for name and quantity",
    "Orders class contains address, payment method, and list of Product objects"
  ],
  "editors_take": null,
  "opinion": false,
  "illustration": null,
  "coverage": {
    "outlets": 1,
    "also_reported_by": []
  },
  "machine_translated": false,
  "ai_generated": true,
  "disclaimer": "Accounts, briefs, key points, the editor’s take and translations are written by software from other outlets’ reporting and may contain errors. A summary whose summary_source is \"publisher\" is the outlet’s own feed text. Always check the linked original."
}