Implementation:Protectai Llm guard Config
Appearance
| Knowledge Sources | |
|---|---|
| Domains | Configuration, API_Design, DevOps |
| Last Updated | 2026-02-14 12:00 GMT |
Overview
Concrete tool for loading and validating YAML-based scanner pipeline configuration using Pydantic models, provided by the LLM Guard API.
Description
The Config class and get_config function load a YAML configuration file, substitute environment variables, and validate the schema using Pydantic. The configuration defines input/output scanner pipelines, authentication, rate limiting, and observability settings.
Usage
Used internally by create_app to initialize the API server. Users author the YAML file; the system loads and validates it at startup.
Code Reference
Source Location
- Repository: llm-guard
- File: llm_guard_api/app/config.py
- Lines: L52-88
Signature
class Config(BaseModel):
input_scanners: List[ScannerConfig] = Field()
output_scanners: List[ScannerConfig] = Field()
rate_limit: RateLimitConfig = Field(default_factory=RateLimitConfig)
auth: Optional[AuthConfig] = Field(default=None)
app: AppConfig = Field(default_factory=AppConfig)
tracing: Optional[TracingConfig] = Field(default=None)
metrics: Optional[MetricsConfig] = Field(default=None)
def get_config(file_name: str) -> Optional[Config]:
"""Load and validate YAML config file."""
Import
from llm_guard_api.app.config import Config, get_config
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| file_name | str | Yes | Path to YAML configuration file |
Outputs
| Name | Type | Description |
|---|---|---|
| Config | Config or None | Validated configuration object, or None if loading fails |
Usage Examples
YAML Configuration File
app:
name: "LLM Guard API"
log_level: "INFO"
scan_fail_fast: false
scan_prompt_timeout: 10
scan_output_timeout: 30
lazy_load: false
auth:
type: http_bearer
token: "${API_TOKEN:default-token}"
input_scanners:
- type: PromptInjection
params:
threshold: 0.92
use_onnx: true
- type: Toxicity
params:
threshold: 0.5
output_scanners:
- type: NoRefusal
params:
threshold: 0.75
- type: Relevance
params:
threshold: 0.5
Related Pages
Implements Principle
Requires Environment
Page Connections
Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment