How to Get Structured Responses back from OpenAI
OpenAI Tip: If you need structured output from the LLM, use structured responses and define the expected format with JSON Schema.
Hereโs an example:
from openai import OpenAI
import os
client = OpenAI(api_key=os.getenv("OPENAI_API_KEY"))
# Define the exact shape you want back.
schema