Language models write plans as structured data: a list of steps, each naming a tool, its arguments and the earlier steps it depends on. Before executing anything, a safe agent checks the plan against what is actually available, because models routinely invent tools that do not exist, omit required arguments, add arguments the tool does not accept and reference steps that come later or never. Catching these statically is cheap, and the error messages are valuable: returned to the model they let it repair its own plan.
Implement validate_plan.
plan is a list of dicts with keys id, tool, args (a dict) and depends_on (a list of step ids). tools maps tool name to {'required': [...], 'optional': [...]}.step {id}: unknown tool '{tool}' and skip the argument checks; otherwise add step {id}: missing argument '{a}' for each required argument absent from args (alphabetical), then step {id}: unexpected argument '{a}' for each argument in neither list (alphabetical).depends_on in the listed order: if it is not the id of an earlier step, add step {id}: invalid dependency '{d}'.Keep a set of the ids seen so far while iterating, so 'earlier step' is a set lookup.
A dependency on a later or unknown step is invalid for the same reason: it is not available yet.
No results yet
Run your code to check it against the examples, or submit to run every test.