promptdojo_promptdojo_promptdojo_promptdojo_promptdojo_promptdojo_promptdojo_promptdojo_promptdojo_promptdojo_promptdojo_

Validate tool inputs — when the model invents arguments — step 8 of 9

Write dispatch_with_validation(tool_name, args) that:

  • Looks up SCHEMAS[tool_name]. If missing, return "UNKNOWN_TOOL: <name>" (don't crash).
  • Runs validate(args, schema). If invalid, return "VALIDATION_ERROR: <error message>".
  • On valid: looks up TOOLS[tool_name], calls it with **verdict["args"], returns the result.

Three cases run for you. Expected output:

results for ramen
VALIDATION_ERROR: missing required field: q
UNKNOWN_TOOL: frobnicate

full-screen editor opens — close anytime to keep reading.