Skip to main content
πŸ”’ Preview mode. The first 15 Foundations lessons are free; this one is Pro. Start a 7-day trial to unlock the editor, AI hints and the the rest of the curriculum. Card required, cancel any time in Dashboard.Start 7-day trial β†’
⚑
← Coursesβ€ΊAI Engineering with PythonModule 2 Β· Tool Use & Function Calling Β· Recapβ€ΊπŸŽ― Review: AI engineering module 2 recapscenario43 / 105
+80 XP
Task
Build `tool_use_with_validation(tool_def, args)` that mirrors the safety check senior engineers wrap around every tool call: 1. Read `tool_def["input_schema"]` (JSON Schema dict with `properties` and `required`). 2. If any `required` key is missing from `args` β†’ return `{"valid": False, "error": "missing:<key>"}`. 3. For each arg present, if the property declares a `type`, check it matches (`"string"`β†’str, `"integer"`β†’int, `"number"`β†’float, `"boolean"`β†’bool). On mismatch β†’ `{"valid": False, "error": "type:<key>"}`. 4. Otherwise β†’ `{"valid": True, "result": "called <name> with <sorted args>"}`. The harness runs 3 scenarios: a clean call, a missing required field, and a type mismatch.
✏️ Write your code here
🐍
Loading Python...
One-time download (~1 MB). Then it runs instantly.
πŸ“Š Result
Press Run to see result...

πŸ’¬ Discussion

Be the first to ask a question or share a tip.
Sign in to join the discussion. Reading is free.
Loading discussion…