Urgent.News

What's breaking now, across hundreds of outlets.

Tech

Structured output with JSON, validated with Pydantic - Chat Orders

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โ€ฆ

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.

Pydantic 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.

The 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.

Several 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.

The 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.

Rewritten by urgent.news; may contain errors โ€” check the original.

Source: dev.to

Read the original at dev.to โ†’

Report a problem with this story

More in Tech

Laptop Camera Not Working on Windows 11? 7 Fixes

Your laptop camera shows a black screen or an error in Zoom, Teams, or the Camera app. Windows 11 blocks camera access in several places, so this is usually a privacy setting or a driver issue, not aโ€ฆ

Myth: CSV Is Just Comma-Separated Values

The name says it: comma-separated values. So the parser is one line: split on commas. I tested that belief with a real run, and a single quoted field broke it.

  • "CSV" stands for "comma-separated values"
  • Parser splits data on commas, fails with quoted fields
  • Flag indicates parser state inside quotes, solves issue

How to Convert PDF to PowerPoint Online for Free โ€” Without Uploading It Anywhere

You have a PDF and you need it as a presentation. A report that has to become slides for a meeting. A lecture handout that needs to be projected.

  • Visit PDF to PowerPoint tool at https://pdfwordtools.pages.dev/pdf-to-powerpoint
  • Upload PDF directly into tool, preserving original text and layout
  • Download converted .pptx file, editable without watermarks

A region code is not a place: 16 collisions in 270 verified cloud regions

Multi-cloud tooling treats region identifiers like a shared vocabulary. They aren't. I pulled the region lists straight from providers' own region pages โ€” 270 rows across 9 providers, every rowโ€ฆ

  • 16 collisions found among 270 verified cloud regions
  • Same region code maps to different geographic locations
  • Provider's code and source URL recommended over region code

More from Tuesday, 1 December 2026 โ†’