mirror of
https://github.com/BerriAI/litellm.git
synced 2026-12-03 01:38:46 +00:00
* init PolicyMatcher * TestPolicyMatcherGetMatchingPolicies * TestPolicyMatcherGetMatchingPolicies * feat: init PolicyResolver * init resolver types * init policy from config * inint PolicyValidator * validate policy * init Architecture Diagram * test_add_guardrails_from_policy_engine * init _init_policy_engine * test updates * test fixws * new attachment config * simplify types * TestPolicyResolverInheritance * fix policy resolver * fix policies * fix applied policy * docs fix * docs fix * fix linting + QA checks * fix linting + QA fixes * test fixes
1.7 KiB
1.7 KiB
Policy Engine Architecture
Overview
The Policy Engine allows administrators to define policies that combine guardrails with scoping rules. Policies can target specific teams, API keys, and models using wildcard patterns, and support inheritance from base policies.
Architecture Diagram
flowchart TD
subgraph Config["config.yaml"]
PC[policies config]
end
subgraph PolicyEngine["Policy Engine"]
PR[PolicyRegistry]
PV[PolicyValidator]
PM[PolicyMatcher]
PRe[PolicyResolver]
end
subgraph Request["Incoming Request"]
CTX[Context: team_alias, key_alias, model]
end
subgraph Output["Output"]
GR[Guardrails to Apply]
end
PC -->|load| PR
PC -->|validate| PV
PV -->|errors/warnings| PR
CTX -->|match| PM
PM -->|matching policies| PRe
PR -->|policies| PM
PR -->|policies| PRe
PRe -->|resolve inheritance + add/remove| GR
Components
| Component | File | Description |
|---|---|---|
| PolicyRegistry | policy_registry.py |
In-memory singleton store for parsed policies |
| PolicyValidator | policy_validator.py |
Validates configs (guardrails, inheritance, teams/keys/models) |
| PolicyMatcher | policy_matcher.py |
Matches request context against policy scopes |
| PolicyResolver | policy_resolver.py |
Resolves final guardrails via inheritance chain |
Flow
- Startup:
init_policies()loads policies from config, validates, and populatesPolicyRegistry - Request:
PolicyMatcherfinds policies matching the request's team/key/model - Resolution:
PolicyResolvertraverses inheritance and applies add/remove to get final guardrails