Validation Engine
Install
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_validArchitecture
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
| Rule | Description |
|---|---|
max_tokens | Reject prompts exceeding a token limit |
no_pii | Reject prompts containing PII patterns |
allowed_models | Restrict which models can be called |
cost_limit | Reject 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())