A fast, validated tool adapter for voice agent lookups
Build availability and booking-proposal tools that check caller identity, validate arguments, time out quickly and fail safely.
By Invicly Tech, , in n8n, AI Automation and Voice Agents. About 7 minutes to read.
In short
A tool adapter is a small service the voice model calls for quick lookups, such as checking availability or proposing a booking. It must answer in well under a second, so it validates inputs, checks who the caller is, sets short timeouts and returns a safe answer when something fails.
Think of it like this: It is the counter clerk who answers quick questions straight away, and says I will check and call you back when the answer takes longer.
Explained simply
While someone is on the phone, every second of silence feels long. So when the voice model needs a fact, like which times are free, it should ask a small, fast service. We call that service a tool adapter.
The adapter does four jobs. It receives the request, checks who the caller is, checks that the arguments make sense and asks your calendar. If anything is wrong or slow, it returns a short, safe message.
Who the caller is must come from your own server, not from the model. The model writes the arguments, and a model can be tricked or can make mistakes. Your session knows who really called.
For anything that needs approval, give the model a propose tool. It records a request. A person or workflow confirms it later.
Press Play on a diagram to walk through it one step at a time.
- 1Tool call arrives
Name and arguments from the model.
- 2Check identity
Session and caller from your own state.
- 3Validate arguments
Types, ranges, allowed values.
- 4Query with timeout
Calendar lookup, short limit.
- 5Return result or safe failure
- Read only
- Fast, under 2 seconds
- Returns a few free times
- Safe to retry
- Writes a request
- Needs an idempotency key
- Returns a proposal ID
- Final approval comes later
In depth
Define the tool schema
A tool is a name, a plain description and a JSON schema for its arguments. Keep it narrow: check_availability takes a date, a zone and a duration. propose_booking takes a start, a zone and a reason. Fewer, clearer tools mean the model picks the right one more often. Use enums for fixed choices and bounds for numbers. The schema guides the model, but it is not a security check.
- One job per tool
- Typed arguments with bounds
- Enums for fixed choices
- Plain descriptions the model can follow
Identity and validation at the service
The adapter looks up the session from a token your server issued and reads the caller from that session. It ignores any caller ID in the arguments. Then it validates every argument again: dates in the future, zone known, duration in range. Doing it at the service protects you even if the schema is loosely enforced or the model sends strange values.
- 1Model
Suggests arguments from speech.
- 2Schema
Guides shape and types.
- 3Service validation
Enforces ranges and rules.
- 4Session identity
Decides who the caller is.
- 5Calendar permissions
Limit what can be read or written.
Timeouts and safe failures
Pick a budget for the whole tool call, for example under two seconds, and set a shorter timeout on the calendar request inside it. When time runs out, return a structured failure with a sentence the model can say. Never include stack traces, internal host names or customer data. Also log the failure with the session ID so you can investigate later.
- Total budget first, then per-call timeouts
- Return ok false plus a spoken sentence
- No internal details in the reply
- Log with the session ID
Propose, do not decide
A booking that needs approval should be a proposal. The tool stores the request and returns a proposal ID. The model then says the booking is requested. This keeps the live call fast and keeps the decision with the people or workflow that own it.
Learn it in 5 short steps
About 35m each. Track them with a timer in your plan.
- 1Define tool schemas~35m
- 2Check session or caller identity~35m
- 3Validate arguments at the service~35m
- 4Set short timeouts~35m
- 5Return safe failure responses~35m
Key points
- Define each tool with a clear name and a typed JSON schema for its arguments.
- Take the caller identity from your session, never from model-written arguments.
- Validate again at the service, even if the schema already checked them.
- Set a short timeout and return a polite failure the model can speak.
- Offer a proposal tool, not a final booking tool, when a person must approve.
Key terms
Tap a card to flip it. 0/5 known
Examples
from pydantic import BaseModel, Field
class AvailabilityArgs(BaseModel):
date: str = Field(pattern=r"^\d{4}-\d{2}-\d{2}$")
time_zone: str
duration_minutes: int = Field(ge=15, le=120)
@app.post("/tools/check_availability")
async def check(args: AvailabilityArgs, session=Depends(current_session)):
try:
return await asyncio.wait_for(find_slots(session.caller_id, args), 1.5)
except asyncio.TimeoutError:
return {"ok": False, "say": "I cannot check just now. Shall I take a message?"}Validated arguments, identity from the session, a 1.5 second limit.
A tool definition
This JSON describes check_availability to the model. Notice there is no caller ID argument.
{
"name": "check_availability",
"description": "List free appointment times on one day.",
"parameters": {
"type": "object",
"properties": {
"date": { "type": "string", "description": "YYYY-MM-DD" },
"time_zone": { "type": "string", "description": "IANA name" },
"duration_minutes": { "type": "integer", "minimum": 15, "maximum": 120 }
},
"required": ["date", "time_zone", "duration_minutes"]
}
}A safe failure
The calendar takes too long. The adapter returns a short structure. The model reads the say field aloud and offers a callback. The caller is not left in silence, and nothing internal is revealed.
{
"ok": false,
"reason": "timeout",
"say": "I cannot check the calendar right now. Would you like a callback?"
}Quick reference
- Keep tools narrow: one job each.
- Never take caller identity from tool arguments.
- Validate at the service even if the schema checks types.
- Set a total budget and a shorter timeout per call.
- Return ok false plus a sentence the model can say.
- Use propose tools when approval is needed.
Common mistakes
- Trusting a caller_id the model passes as an argument.
- No timeout, so a slow calendar leaves silence on the line.
- Returning raw error text that includes internal names.
Quick quiz
Pick an answer to see if you're right and why.
Practice exercises
Try each one yourself first. Use the hint if you get stuck, then compare with the solution.
- Exercise 1easy
Write a one-line description for check_availability that the model can follow.
- Exercise 2medium
List the validation rules for check_availability arguments.
- Exercise 3hard
Sketch a FastAPI handler that returns a safe failure on timeout and validates input with Pydantic.
Check yourself
Answer in your head, reveal, then be honest with yourself.
Feel confident about this topic?
Frequently asked questions
- How fast must a tool respond?
- As fast as you can. Aim for well under two seconds, because the caller is waiting in silence.
- Can the model call my database directly?
- It should not. Put a service in between that checks identity and validates arguments.
- What if a tool is called twice?
- Make write tools idempotent with a key, so a repeat does not create a second request.