- Instant Validation
- Complete Predictability
- Three Validation Modes
When you need to ensure legal disclaimers appear in LLM outputs, block sensitive information in user inputs, or verify required sections exist in generated documents, you need validation that happens instantly without waiting for LLM analysis.Contains string provides sub-10ms response times with zero cost since it runs locally using simple pattern matching. This makes it perfect as a front-line filter before more expensive LLM-powered guardrails.
How Contains String Works
Understanding the validation process helps you choose the right mode and configure effective string lists:Content submission with configuration
You send text to the contains string guardrail along with your configuration: a list of strings to check for, which mode to use (ANY, ALL, or NONE), and optionally whether to use case-sensitive matching. The configuration determines exactly how the validation behaves.
Pattern matching execution
The guardrail performs simple string matching against your content. This happens locally on ABV’s infrastructure without any LLM calls, making it instant (under 10ms) and free.ANY mode: Checks if at least one string from your list appears in the text. Passes when any match is found.ALL mode: Checks if every string from your list appears in the text. Passes only when all strings are present.NONE mode: Checks that no strings from your list appear in the text. Passes only when zero matches are found.By default, matching is case-insensitive (“Password” matches “password”). Enable case-sensitive matching when exact capitalization matters.
Deterministic result
The guardrail returns a result indicating pass or fail. Since this is rule-based validation, there’s no “unsure” status—the result is always definitive. The confidence is always 1.0 because pattern matching has no uncertainty.The reason field explains which strings were found or missing. Log this internally for debugging and analysis, but as with all guardrails, never expose detailed reasons to end users to prevent evasion learning.
Automatic observability
Every validation automatically creates an observation in ABV capturing the input text, result, configuration (strings, mode, case sensitivity), and performance metrics. This happens even though the guardrail is free to use, giving you visibility into validation patterns and helping you tune your string lists over time.
When to Use This Guardrail
Contains string excels in specific scenarios where you can enumerate exactly what to check:Legal Disclaimer Enforcement
Legal Disclaimer Enforcement
Regulatory requirements often mandate specific disclaimers in generated content. Financial advice requires “not financial advice,” medical content needs liability disclaimers, and general-purpose LLM outputs benefit from clarity statements.Use ANY mode to accept multiple valid phrasings of the same disclaimer, giving content creators flexibility while ensuring compliance. Check instantly before showing content to users.
Sensitive Information Blocking
Sensitive Information Blocking
Users sometimes share passwords, credit card numbers, social security numbers, or other sensitive information they shouldn’t submit to LLMs. These inputs create security risks and compliance violations.Use NONE mode to block content containing forbidden terms like “password,” “SSN,” “credit card,” and “bank account.” This pre-filtering happens instantly, blocking obvious violations before more expensive content analysis.
Required Section Verification
Required Section Verification
Generated documents, emails, and content often need specific elements for compliance or quality. Marketing emails need unsubscribe links, privacy policy links, and copyright notices. Generated contracts need specific clauses.Use ALL mode to ensure every required element appears. If any element is missing, the validation fails, preventing incomplete content from reaching users or requiring manual review.
Competitor Mention Prevention
Competitor Mention Prevention
Marketing content, product descriptions, and customer communications should avoid mentioning competitor brands. Even indirect references can violate brand guidelines or create legal issues.Use NONE mode with a comprehensive list of competitor names, product names, and domain names. The instant validation catches mentions before content is published.
Fast Pre-Filtering Before Expensive Checks
Fast Pre-Filtering Before Expensive Checks
When combining multiple guardrails, run the fastest checks first. Contains string costs nothing and responds in under 10ms, while LLM-powered guardrails take 1-3 seconds and consume tokens.Use contains string to catch obvious violations instantly, then only run expensive LLM-powered checks on content that passes the initial filter. This pattern dramatically reduces costs and latency.
Understanding Match Modes
The three modes fundamentally change validation behavior. Choosing the right mode is essential:ANY Mode (OR Logic)
Behavior: Content passes when at least one string from your list appears. Use cases:- Legal disclaimers where multiple phrasings are acceptable
- Detecting any of several forbidden categories
- Ensuring at least one required element exists
- TypeScript/JavaScript
- Python
ALL Mode (AND Logic)
Behavior: Content passes only when every string from your list appears. Use cases:- Email compliance requiring unsubscribe link, privacy policy, and copyright
- Document templates needing all required sections
- Quality checks ensuring completeness
- TypeScript/JavaScript
- Python
NONE Mode (NOT Logic)
Behavior: Content passes only when zero strings from your list appear. Use cases:- Blocking sensitive information (passwords, credit cards, SSNs)
- Preventing competitor mentions
- Filtering forbidden terms before expensive checks
- TypeScript/JavaScript
- Python
Case-Sensitive Matching
By default, matching is case-insensitive: “PASSWORD,” “Password,” and “password” all match. This catches variations in how people write. Enable case-sensitive matching when exact capitalization matters:- TypeScript/JavaScript
- Python
Implementation Patterns
Legal Disclaimer Validation
Ensure LLM-generated content includes appropriate disclaimers while allowing flexibility in phrasing:- TypeScript/JavaScript
- Python
Sensitive Information Blocking
Prevent users from sharing sensitive information that creates security and compliance risks:- TypeScript/JavaScript
- Python
Email Compliance Verification
Ensure all required elements appear in marketing emails for CAN-SPAM and other compliance:- TypeScript/JavaScript
- Python
Efficient Pre-Filtering Pattern
Use contains string as a fast pre-filter before expensive LLM-powered guardrails:- TypeScript/JavaScript
- Python
Building Effective String Lists
The effectiveness of contains string depends entirely on the quality of your string lists:Blocking Sensitive Information
Blocking Sensitive Information
Cast a wide net by including variations. Rather than just “password,” include “pwd,” “pass,” “passcode,” “pw.” For credit cards, include “credit card,” “cc,” “card number,” “mastercard,” “visa,” “amex.”Pattern: Think about every reasonable way someone might express the concept, including abbreviations, common misspellings, and related terms.
Requiring Disclaimers
Requiring Disclaimers
Offer multiple phrasings that accomplish the same legal purpose. For financial advice disclaimers: “not financial advice,” “consult a financial professional,” “for informational purposes only,” “not investment advice.”Pattern: All variations protect you legally while giving content creators flexibility in exact wording.
Competitor Blocking
Competitor Blocking
Be comprehensive. Include company names, product names, domain names, and common misspellings. For “CompetitorCo”: also include “competitor-co,” “competitorco,” “competitor.com,” “CompetitorCorp.”Pattern: Cover official names, informal names, domains, and variations people actually use when mentioning competitors.
Case Sensitivity Decisions
Case Sensitivity Decisions
Use case-insensitive matching (default) for general terms where capitalization varies. Use case-sensitive matching for brand names (“iPhone” not “iphone”), proper nouns, and technical terms where capitalization has specific meaning (“JavaScript” vs “javascript”).Pattern: Case-sensitive when exact form matters for correctness or brand identity. Case-insensitive for broader coverage of general terms.
Combining with Other Guardrails
Contains string works particularly well as part of layered validation: Sequential filtering pipeline: Run contains string first (instant, free) to catch obvious violations, then run LLM-powered guardrails (1-3 seconds, token cost) only on content that passes. This dramatically reduces costs while maintaining comprehensive protection. With toxic language detection: Block explicitly forbidden slurs with contains string, then use toxic language detection for context-aware analysis of everything else. The contains string pre-filter catches the obvious cases instantly. With valid JSON: When LLM generates JSON, validate JSON structure first (instant), then use contains string to verify specific required fields exist before checking content quality with LLM-powered guardrails. With biased language detection: Block obviously discriminatory terms with contains string, then use biased language detection for subtle coded language and contextual bias. Two-layer protection at different speeds and costs.Next Steps
Best Practices
Learn optimal patterns for combining guardrails, error handling, and cost optimization
Toxic Language
Add context-aware toxicity detection after contains string pre-filtering
Valid JSON
Combine with JSON validation for structured LLM outputs
Concepts
Understand layered validation patterns and decision strategies