AI-powered validators for semantic matching and language detection
LLM validators use AI models to evaluate content that can’t be easily checked with exact matching. They’re ideal for validating natural language outputs where wording may vary but meaning should be consistent.
LLM validators support transforms. Transforms are applied to the content before sending to the LLM for evaluation.
Uses an LLM to check if the actual value semantically matches the expected description.
Copy
output: semantic!: "A polite greeting that welcomes the user"
Parameter
Type
Description
value
string
Natural language description of expected content
The semantic validator sends the actual value and your description to an LLM, which determines if they match semantically.
Examples
Copy
# Time response validationoutput: semantic!: "a time response mentioning Madrid"# Error handlingoutput: semantic!: "An apologetic message explaining the service is unavailable"# Product descriptionoutput: semantic!: "A detailed product description including price and availability"# Professional toneoutput: semantic!: "A professional response suitable for a business context"
Be specific about what you expect. Vague descriptions lead to inconsistent results.
Good prompts:
Copy
# Specific and measurablesemantic!: "A response that includes at least 3 product recommendations with prices"semantic!: "An error message that mentions the specific field that failed validation"semantic!: "A summary that covers the main points: budget, timeline, and deliverables"
Avoid:
Copy
# Too vaguesemantic!: "A good response"semantic!: "Something helpful"semantic!: "The right answer"
Output wording can vary but meaning must be consistent
Testing for tone, style, or completeness
Validating summaries or explanations
Use exact matching (eq!, contains!) when:
Specific words or phrases must appear
Validating structured data
Checking for exact values
Copy
# Use semantic for flexible contentoutput: semantic!: "Confirms the order was placed successfully"# Use contains for required termsoutput: contains!: "Order #"# Combine both approachesoutput: contains!: "confirmed" semantic!: "A professional confirmation with order details"
Checks that the content does NOT semantically match the description. This is the negated form of semantic!.
Copy
output: not_semantic!: "An error message or apology"
Parameter
Type
Description
value
string
Natural language description that must NOT match
Examples
Copy
# Ensure response is not an erroroutput: not_semantic!: "An error message or failure notification"# Ensure not rude or dismissiveoutput: not_semantic!: "A rude, dismissive, or unhelpful response"# Ensure not off-topicoutput: not_semantic!: "A response about unrelated topics"
- name: professional_tone runnable: agent.py::agent params: prompt: "I want a refund" output: semantic!: "A professional, empathetic response that acknowledges the request and explains the refund process"- name: casual_tone runnable: agent.py::agent params: prompt: "Hey what's up" output: semantic!: "A casual, friendly greeting that matches the user's informal tone"
output: semantic!: | A comprehensive response that includes: - Acknowledgment of the user's question - Direct answer to the question - Additional context or helpful information - Offer for follow-up assistance
- name: helpful_error_message runnable: agent.py::agent params: prompt: "Buy product XYZ123" output: semantic!: | An error message that: - Clearly states the product was not found - Suggests possible alternatives or corrections - Offers help finding the right product
Transforms normalize content before LLM evaluation:
Copy
# Normalize whitespace before semantic checkoutput: semantic!: value: "A professional greeting" transform: [trim, collapse_whitespace]# Lowercase before language detectionoutput: language!: value: "en" transform: lowercase