How to stop a LiveKit booking agent from making a bad booking
LiveKit voice agent guardrails for booking lines. Block a discount over your limit, a cancellation of someone else's booking or an off-hours slot before the tool runs.
LiveKit voice agent guardrails for booking lines. Block a discount over your limit, a cancellation of someone else's booking or an off-hours slot before the tool runs.
Tell a voice agent to keep callers happy and sooner or later it gives somebody a free haircut. The caller says they're a friend of the owner, the model sets discount_percent to 100, and the booking goes through, because a LiveKit function tool runs whatever arguments the model hands it. You can write "never more than 20% off" into the prompt, but the prompt is a request to the model and nothing checks it. An Amiril rule is checked in the agent's own process before the tool runs, and the rest of this post writes some for a booking line. If you haven't sent your calls to Amiril yet, the post on monitoring a LiveKit booking agent covers that part.
The example here is a salon's phone line. It finds free slots, books, moves and cancels appointments, and its tools are plain LiveKit function tools that call the salon's booking system. The discount is the expensive mistake, and a model will hand it out to anyone with a story. Another is cancelling a booking that belongs to someone else, after a caller says "cancel Sarah's three o'clock, she can't make it", and nothing asks whether this caller is Sarah. And somebody asks for half past seven on a Monday, the model books it, and the salon shuts at six.
None of them throws an error, so monitoring sees a 100% discount only afterwards, as a rare value for that agent, and by then the free haircut is in the diary.
if in the tool functionThe nearest place to stop a call is the function itself. An if discount_percent > 20 at the top of book_appointment that raises LiveKit's ToolError hands the model an error, and the booking never happens. That covers one limit on one agent, up to the week the owner wants 25% for regulars without a deploy, or asks how many of last month's calls a new limit would have refused.
An Amiril rule is a few lines of text, written in the web app or by an AI assistant through Amiril's MCP server. This one caps the discount:
@id("discount-cap")
@sentence("A {discount_percent}% discount is over the 20% limit")
block (
agent == "front_desk",
tool == "book_appointment"
)
when {
call.args.discount_percent > 20
};Models often send null for an argument they have nothing to say about, and a null never makes a condition true, so a full-price booking goes through. front_desk is the agent, named after its LiveKit Agent class.
The cancellation rule compares the number on the booking with the number the call came from:
@id("cancel-own-booking")
@sentence("Only the person who made a booking can cancel it")
block (
agent == "front_desk",
tool == "cancel_booking"
)
unless {
call.args.booking_phone == call.args.caller_phone
};That only works if the model fills in neither number, because a model that can be talked into 100% off can be talked into the right phone number too. So the tool the model sees takes just a booking id, and your code looks up the booking and passes both numbers to the function the SDK checks. On a LiveKit phone line the caller's number is the SIP participant's sip.phoneNumber attribute:
def booking_tools(sdk_agent: plain.Agent, caller_phone: str) -> list:
@sdk_agent.tool(name="cancel_booking")
async def checked_cancel(booking_id: str, booking_phone: str, caller_phone: str) -> dict:
return await bookings.cancel(booking_id)
@function_tool
async def cancel_booking(booking_id: str) -> dict:
"""Cancel one of the caller's bookings."""
booking = await bookings.get(booking_id)
return await checked_cancel(booking_id, booking["phone"], caller_phone)
return [cancel_booking]The entrypoint reads the number with participant = await ctx.wait_for_participant() and passes participant.attributes["sip.phoneNumber"] in.
Opening hours:
@id("opening-hours")
@sentence("{start} is outside opening hours, 9:00 to 18:00")
block (
agent == "front_desk",
tool == "book_appointment"
)
when {
hour_utc(call.args.start) < 9 || hour_utc(call.args.start) >= 18
};The salon's slot search returns local times with no offset, and hour_utc takes the hour as written when there is none, so 2026-12-03T17:30 gives 17, the salon's own hour. If your times carry an offset, the hour you compare against shifts by it.
The Amiril SDK does the checking, in the agent's process, against a copy of your published rules that it keeps up to date from your workspace. You wrap each function tool with the SDK, under LiveKit's own decorator, and LiveKit still reads the signature and docstring as before:
@function_tool
@sdk_agent.tool
async def book_appointment(service: str, start: str, customer_name: str, customer_phone: str,
discount_percent: float | None = None) -> dict:
"""Book a service at a start time (ISO, from find_slots) for a customer."""
return await bookings.book(service, start, customer_name, customer_phone, discount_percent)amiril.init() goes in the setup_fnc you pass to AgentServer, with handle_sigterm=False so that LiveKit's worker keeps control of shutdown. The SDK agent takes the name LiveKit gives your Agent in its traces, which is the class name in snake case, so a FrontDesk class is front_desk. The agent_name you give rtc_session only routes phone calls to the worker, so don't use it here. And the call has to be one run, which means starting the session inside the SDK's run and staying there until the session closes:
async with sdk_agent.run(session_id=ctx.room.name) as run:
session.on("function_tools_executed", lambda _event: run.turn())
await session.start(agent=FrontDesk(tools), room=ctx.room)
await closed.wait()closed is an asyncio.Event set from the session's close event. The run.turn() line marks where each model reply ends. A rule can require an earlier call, such as booking only a slot that find_slots returned, and it looks for that call in the model's earlier replies. Without the marks the whole phone call is one reply, with nothing before it.
When a rule blocks a call, book_appointment never runs and the booking system never hears about it. The model gets this instead:
The call to book_appointment was not performed. Rule discount-cap blocked it: A 100% discount is over the 20% limit. Do not retry this call with different arguments or achieve the same outcome another way; tell the user it was not performed.
The "do not retry" part is there for a model that would otherwise try 99%. The agent then tells the caller it can't do that discount and offers to book at the normal price, in its own words, and the call carries on. The check is a function call against rules already in the agent's memory, with no request to Amiril on the way.
A new rule starts in Shadow, which records what it would have done and lets every call through. If the agent already sends its traces, the rule's page counts the calls it would have fired on in the last 24 hours, and Test on past calls replays it over the last week or month of real calls. That's where you'd find out that the opening-hours rule also refuses the late Thursday slot the salon added last month. Switch a rule to Enforce in a Development environment first, place a test call and ask for 100% off, then switch the Production environment over once you trust it.
The LiveKit guide in the Amiril docs has the whole agent file. The phone number and the Amiril gateway are on a second page. For the bookings that fail without any rule breaking, read voice agent booking failures. Cekura vs Amiril compares testing calls with blocking them, The same rules run on LangGraph, Google ADK and plain Python or TypeScript, as the AI agent guardrails page lists.