Back to notes
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 doc

Real 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.

  1. Replace nested objects with explicit top-level fields when possible.
  2. Use IDs, enums, and short strings instead of free-form nested payloads.
  3. Move derived values into server-side lookup logic.
  4. Return validation errors that explain exactly which field failed.
  5. 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
Practical note
If a value can be derived from a trusted ID, derive it on the server instead of asking the model to send it.

Use this as an implementation constraint, not just advice. The interface, server code, and validation path should make the same behavior true.

Apply this to a build
Contact
Bring the product pressure, system constraints, and expected business outcome.
Send the desired outcome, users, current bottleneck, stack, and timeline. I will respond with a practical senior engineering path for the build.