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. Intro to Structured Output — Structured output is necessary for agents to reliably consume LLM responses.
  2. Defining the Schema — Pydantic models are used to define the required data structure and generate the necessary JSON schema.
  3. Enforcing JSON Mode — The LLM API must be configured with JSON mode and the schema to guarantee valid output.
  4. Grounding and Refusal — Grounding discipline requires the model to strictly adhere to the task and refuse OOD queries.
  5. Testing OOD Robustness — Testing with out-of-scope questions ensures the structured refusal mechanism functions correctly.
PDF notes

Frequently asked questions

Why is using JSON output better than just asking for a list in text?

JSON output guarantees machine readability and type consistency, allowing direct parsing into Python objects without fragile regex or NLP parsing steps.

What is an Out-of-Distribution (OOD) prompt?

An OOD prompt is a query that falls outside the scope of the task defined in the system prompt, such as asking for general knowledge during a strict data extraction task.

How does Pydantic help with structured extraction?

Pydantic defines the required data types and structure (schema) upfront, and its schema can be passed directly to the LLM API to enforce output validation and consistency.

What is the "grounding pattern" mentioned in the source notes?

The grounding pattern refers to the disciplined approach of limiting the LLM's knowledge base strictly to the provided context or task definition, often enforced via system prompts.

How was this lesson?

Your feedback helps us refine explanations and catch bugs.