Contains
Checks whether the agent output contains (or doesn't contain) specific strings.
Config
| Field | Type | Required | Default | Description |
|---|---|---|---|---|
value | string or string[] | Yes | — | Substring(s) to check for |
case_sensitive | boolean | No | false | Case-sensitive matching |
mode | string | No | any | any (at least one) or all (every string) |
negate | boolean | No | false | Pass if string is NOT found |
Use Cases
- Guardrail checking — Ensure your agent never says "I don't know", "As an AI", or leaks PII patterns. Use
negate: trueto fail when a forbidden phrase appears. - Compliance and disclaimers — Verify that every response includes required language such as "This is not financial advice" or "Please consult a professional."
- Content validation — Confirm that the agent mentions specific product names, features, or data points that should always appear in a response to a given query.
- Multi-criteria checks — Combine
mode: "all"with an array of values to assert that an agent covers every required topic in a single response.
Examples
Basic match
// Pass if output mentions "refund"
{
"value": "refund",
"case_sensitive": false
}Negation — block unwanted phrases
// Pass if output does NOT contain "I don't know"
{
"value": "I don't know",
"negate": true
}Multiple values with any mode (default)
// Pass if output contains at least ONE of these phrases
{
"value": ["refund", "return policy", "money back"],
"mode": "any"
}
// Agent says "You can request a refund within 30 days" → pass
// Agent says "Contact support for help" → failMultiple values with all mode
// Pass if output contains ALL of these
{
"value": ["price", "availability", "shipping"],
"mode": "all"
}
// Agent says "The price is $29, it's in stock, shipping takes 3 days" → pass
// Agent says "The price is $29, it's in stock" → fail (missing "shipping")Common Negation Patterns
Combine negate: true with an array of values to block entire categories of unwanted output. When negating, mode: "any" means "fail if ANY of these appear" — which is usually what you want.
// Block hallucination hedging phrases
{
"value": [
"I don't know",
"I'm not sure",
"I cannot help",
"As an AI language model"
],
"mode": "any",
"negate": true
}
// Block PII patterns in output
{
"value": ["@gmail.com", "@yahoo.com", "SSN", "social security"],
"mode": "any",
"negate": true
}
// Ensure compliance disclaimer is NOT missing
// (negate + all = fail only if ALL phrases are absent)
{
"value": ["not financial advice", "consult a professional"],
"mode": "all",
"negate": false
}Scoring
Returns 1.0 (pass) or 0.0 (fail). No intermediate scores.
Performance
Contains runs a simple substring search with no external API calls. Execution time is under 1ms regardless of output length, making it ideal for high-volume pipelines where you need to evaluate every trace without adding latency or cost.