many-controller-54194
10/10/2025, 12:53 AMtall-airline-16756
10/10/2025, 12:53 AMtall-airline-16756
10/10/2025, 12:54 AM@function_tool method, where you check the input and can return None to keep the user in the current agent until the data is valid. For example, in a CollectNameAgent, the collect tool might look like this to make sure the name isn’t empty:
@function_tool
async def collect(self, value: str) -> Optional[Agent]:
value = value.strip()
if not value:
await self.session.say("I didn't catch that. Please tell me your name.")
return None # Stay in current agent
sd: SurveyData = self.session.userdata
sd.record(self.label, value)
self.session.state[self.key] = value
return await self.transition()
Similarly, for validating emails in CollectEmailAgent, you can do a simple format check like this:
@function_tool
async def collect(self, value: str) -> Optional[Agent]:
value = value.strip().lower()
if "@" not in value or "." not in value:
await self.session.say("That doesn't seem like a valid email. Please try again.")
return None
sd: SurveyData = self.session.userdata
sd.record(self.label, value)
self.session.state[self.key] = value
return await self.transition()
To help make your validation even more effective, here are a few tips:
• Use @function_tool methods to both validate and clean up input.
• Return None when the input isn’t valid yet, so users stay where they need to be.
• Leverage session.userdata with structured dataclass models to keep track of progress and completeness.
• Apply formatting helpers like proper_capitalize to keep data consistent and neat.
If you’d like, I’d be happy to help you set up validation rules for other data types, like phone numbers or dates. Or, if you want to enhance the user experience with frontend feedback—maybe using RPC to highlight form fields—I can guide you through that too. Just let me know what you need!
Sources: flows/README.md | Workflows | LiveKit Docs | Tool definition and use | LiveKit Docsmany-controller-54194
10/10/2025, 1:01 AMtall-airline-16756
10/10/2025, 1:02 AMformat: "uuid" to make sure the input matches the standard UUID format (like 12345678-1234-1234-1234-1234567890ab):
{
"type": "string",
"format": "uuid"
}
2. Birthdate Validation
For birthdates, using format: "date" works great for the YYYY-MM-DD format, or format: "date-time" if you need full date-time inputs:
{
"type": "string",
"format": "date"
}
3. Phone Number Validation
• Try using the allowed_numbers field in your SIP trunk configuration to restrict calls to numbers you’ve already validated.
• Also, during agent workflows, confirming phone numbers explicitly during interactions before saving them really helps keep things accurate.
4. Address Validation
Address validation isn’t built-in natively, but here are some friendly ways to handle it:
• Custom Regex Patterns: You can create structured tool parameters with clear hints like "street, city, state, ZIP code" to guide users.
• External Validation: Using geocoding APIs like Google Maps or postal code libraries can help verify addresses after you capture them.
• Two-Step Confirmation: Asking users to confirm their address after you read it back is a simple and effective way to catch errors.
5. Declarative Flow Integration
Another great tip is defining structured input tools with zod in TypeScript or pydantic in Python. These help enforce your validation rules, and LiveKit can convert these into grammar rules that guide input during conversations.
If you'd like, I’d be happy to walk you through detailed examples tailored to your specific workflow. Just let me know!
Sources: examples/src/restaurant_agent.ts | examples/voice_agents/restaurant_agent.py | SIP Integration & Telephony | livekit/livekit_composite | DeepWiki | tests/test-grammar-llguidance.cpp | SIP APIs | LiveKit Docs