Back to notes
Apply this to a build
Tool reliabilityChecklist5 min
Flatten tool schemas for more reliable arguments
A practical pattern for making model-generated tool arguments easier to validate and debug.
Open source docReal workflow example
A CRM assistant tries to create a follow-up task with nested objects for contact, company, deal, owner, priority, and due date. The model regularly misses one nested field.
Flatten the tool input to contactId, dealId, dueDate, priority, and note. The server derives company, owner, workspace, and permissions from trusted records.
Tool calls become easier to validate, logs become readable, and the model stops inventing nested ownership data.
Implementation approach
This guide is anchored in OpenAI function calling guide. Use the official API behavior as the boundary, then design the surrounding product state so the feature can be reviewed, retried, and improved.
- Replace nested objects with explicit top-level fields when possible.
- Use IDs, enums, and short strings instead of free-form nested payloads.
- Move derived values into server-side lookup logic.
- Return validation errors that explain exactly which field failed.
- Add fixtures for the most common tool argument mistakes.
Flat tool payload
type CreateFollowUpInput = {
contactId: string;
dealId: string;
dueDate: string;
priority: "low" | "normal" | "high";
note: string;
};
Field notes
- Deeply nested tool schemas increase validation failures and make logs harder to read.
- Flat inputs make it easier to reject unsafe actions and explain required fields.
- Complexity belongs in your server code, not in model-generated arguments.
Mistakes to avoid
- Do not ask the model to construct nested database records.
- Do not accept ownerId, organizationId, or role values from tool arguments.
- Do not hide validation failures from the user or logs.
Ready checklist
- No avoidable nested argument objects
- Enums for workflow state
- Server derives trusted values
- Validation errors are logged
- Fixtures cover malformed calls
