Command Palette

Search for a command to run...

Hectal
Phase 4: Structured Output
LLM Engineering · Exercise 1 of 6Next
Beginner

Build a JSON Schema from a field list

Write build_schema(fields). fields is a list of (name, kind, required) tuples. kind is either a type name such as "string" or "integer", or a list of allowed strings, which becomes {"type": "string", "enum": [...]}.

Return a dictionary with the keys type ("object"), properties, required (the names of required fields, in order) and additionalProperties (False).

What Check tests

  1. Plain types and the required list
  2. A list of values becomes an enum of strings
  3. No required fields gives an empty list
  4. Extra keys are forbidden

Stuck? One hint at a time

The solution unlocks after your first Check. Try first: that is where the learning happens.

main.py
Sign in to run your code.

Output

Press Run to see what your program prints.