structured output — making the model return json8 / 9
schemas, pydantic, and validation — making the model return real data
Build the parse-and-validate step. Write a function extract_user(raw)
that takes a JSON string the model returned, parses it with
json.loads, validates that:
nameis present and astrageis present and anint
If the JSON is missing a field or has the wrong type, return the
string "invalid". Otherwise return the parsed dict.
Then the script will call it on a good response and print the name.
Expected output:
priya
⌘↵ runs the editor.
Booting Python…
Output
[promptdojo:~]$ _