
Setup
Create a file namedbetter-tools.py with:
- an OpenAI API client
- a short system prompt
- a loop that inspects model responses for function (tool) calls and dispatches them to handlers
Demonstration: vague tool definitions
Begin with two intentionally vague tools so you can observe the problem:Goals
Make the agent:- consistently choose the right tool for a given user intent
- pass well-formed, normalized parameters that your backend expects
- avoid brittle values that cause downstream failures
- Precise descriptions (teach the model when to call each tool)
- Parameter constraints (enums, types, required fields)
- Poka-yoke input normalization inside handlers (normalize inputs in code)
1) Precise descriptions (rename tools and explain when to use them)
Provide explicit tool names and descriptions that tell the model:- What the tool does
- When to call it (in plain language)
- The return shape or what the tool will return
2) Parameter constraints (use enums and clear parameter types)
Constrain parameter values so the model selects supported values only. Add descriptions, enums, and clear typing so your tool contract is unambiguous. Example: adding an enum tocategory ensures the model provides a supported category:
- Prevents unsupported labels like
diningorrestaurantthat your backend doesn’t expect - Produces consistent payloads to your handlers
- Makes validation straightforward on the server side
3) Poka-yoke normalization (input normalization in handlers)
Handle small variations in inputs inside your tool implementation so the model doesn’t need to perfectly match your backend’s vocabulary. Normalization is a defensive, internal measure that reduces errors. Example handler with normalization:- Trim whitespace:
" ITALIAN "→"italian" - Lowercase:
"Italian"→"italian" - Map synonyms:
"cheap","$","1"→"cheap"
Example: predictable end-to-end flow
After applying precise descriptions, parameter constraints, and input normalization, the same prompt:Summary: Quick reference
Next steps & references
- Implement the exact tool definitions in your agent registration (as shown above).
- Add server-side validation to catch unexpected values and return helpful errors.
- Log model tool calls during testing to confirm the model chooses the intended tool consistently.
- OpenAI API reference: https://platform.openai.com/docs/api-reference
Design tool descriptions to be explicit about purpose, expected inputs, and return shapes. Combine parameter constraints (enums, types, required fields) with internal input normalization to make tool usage reliable and robust.