Skip to content

Validation Engine

Install

Terminal window
pip install briefcase-ai[validate]

Quick Example

from briefcase.validate import PromptValidationEngine
engine = PromptValidationEngine()
engine.add_rule("max_tokens", max_value=4096)
engine.add_rule("no_pii", patterns=["SSN", "credit card"])
result = engine.validate(prompt="Summarize this document")
assert result.is_valid

Architecture

The validation engine runs a pipeline of rules against each prompt before it reaches the model. Rules are composable and can be loaded from configuration files.

flowchart LR
    A["Prompt"] --> B["PromptValidationEngine"]
    B --> C["max_tokens"]
    B --> D["no_pii"]
    B --> E["allowed_models"]
    B --> F["cost_limit"]
    C & D & E & F --> G{"All pass?"}
    G -- Yes --> H["Send to model"]
    G -- No --> I["Reject"]

Built-in Rules

RuleDescription
max_tokensReject prompts exceeding a token limit
no_piiReject prompts containing PII patterns
allowed_modelsRestrict which models can be called
cost_limitReject if estimated cost exceeds threshold

Custom Rules

from briefcase.validate import Rule
class MyRule(Rule):
def check(self, prompt: str) -> bool:
return "forbidden" not in prompt
engine.add_rule(MyRule())