Command Palette

Search for a command to run...

Hectal
Phase 4: Structured Output
LLM Engineering · Exercise 2 of 6 PreviousNext
Beginner

Validate a reply and say what is wrong

Write validate(data, spec) where data is a dictionary and spec maps field names to "string", "integer" or "boolean". Return a list of problems, in the order of spec.

A field that is not in data gives "<name>: missing". A field of the wrong type gives "<name>: expected <wanted>, got <found>", where the found type is one of string, integer, boolean or other. Remember that True is not an integer here. A good reply gives [].

What Check tests

  1. A good reply gives no problems
  2. A missing field
  3. A wrong type
  4. True is not an integer
  5. Several problems, in spec order

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.