Back to M0 — Prompting + LLM APIs

Prompting + Structured Extraction

Outcome: Emit valid JSON extraction + refusal on OOD Curated video (Telusko): Getting Structured Output in JSON format — https://www.youtube.com/watch?v=CllLqPwCjD4 (verified live via yt-dlp 2026-09-24). Pointer: llms-genai-for-practitioners/10 (question.py grounding pattern); shell: courses/video-scripts/genai-rag-agents/01.md.

9 minutesVideo LessonPDF notes
🎯 Free Guest Mode: You are learning for free. Sign in to save your completion progress and quiz answers.

Ready to continue?

Mark this lesson as complete when you're ready to proceed.

Key moments

  1. Data Transfer Formats — Applications typically transfer data using structured formats like JSON or XML.
  2. Problem with Text Output — AI responses in text format are hard to parse reliably due to variability and extra content.
  3. Context and Source Injection — Adding a source URL to the prompt ensures the AI uses updated and specific information.
  4. Requesting JSON Output — Instructing the AI to return data in JSON format makes it parsable for applications.
  5. Issue: Extra Text in JSON — Simple JSON requests often result in additional explanatory text surrounding the JSON object.
  6. Enforcing Valid JSON — Use specific instructions to ensure the output is only a valid JSON object with no extra text.
  7. Developer Perspective — Developers need specific, limited properties defined in an object, not all available data.
  8. Defining Output Schema — Specify a role, instructions, and a strict schema to control the exact JSON structure returned.
PDF notes

Frequently asked questions

Why is JSON preferred over plain text for AI output?

JSON is a standard format for data transfer and maps directly to objects in programming languages like Java or Python, making it easily parsable.

What is the risk of using simple text output from an AI?

AI text output is non-standard and unpredictable; it might include extra explanations or vary in format, making reliable parsing impossible.

How do I prevent the AI from including extra text outside the JSON?

Use explicit instructions like "Respond only with valid JSON object and do not include any text or explanation."

Why define a strict schema if the AI already returns JSON?

A strict schema ensures you only receive the specific data fields required for your application, avoiding unnecessary data like USB speed or optical zoom details.