Function calling design
A structured recipe for designing reliable function-calling schemas that LLMs can invoke correctly on the first attempt.
1. Name with intent
Use verb_noun naming. Prefer search_documents over ambiguous shorthand. The name is the model's primary dispatch key.
2. Flat parameters
Avoid nested objects. LLMs handle flat string/number/boolean parameters with far higher accuracy. Flatten before you ship.
3. Enums over free text
Constrain choices with string enums. A parameter namedsort_order with values asc /desc eliminates hallucinated variants.
4. Description density
Every parameter needs a one-sentence description that includes format, constraints, and an example. The model reads these descriptions verbatim — make them count.
5. Required-first ordering
List required parameters before optional ones. Models exhibit recency bias; trailing optional fields are frequently omitted unless explicitly prompted.
Pro tip
Test your schema against 3 different models. If any model consistently mis-invokes a function, the schema is the bug — not the model.