How it-nilesh/llm-guard works
LLM Guard is a Python toolkit for securing LLM interactions. Its main workflow sanitizes and validates a prompt with input scanners, then scans the generated response with output scanners; callers can also use the API’s prompt/output analyze and scan endpoints. Scanner implementations include PII anonymization, injection and content checks, and response-quality and safety checks. The API configures scanners and shares a vault for reversible anonymization. Relationships reflect the README, excerpts, and SOURCE INDEX references; unsampled scanner implementations are represented by their source directories.
Main entry points: input_scanners Input scanner catalog · anonymize.py PII anonymization · scanner.py Scanner orchestration · evaluate.py Evaluate workflow
Components 25
Scan runtime
- Evaluate workflow
llm_guard/evaluate.py - Input scanner contract
llm_guard/input_scanners/base.py - Output scanner contract
llm_guard/output_scanners/base.py - Placeholder vault
llm_guard/vault.py
Prompt security
- Input scanner catalog
llm_guard/input_scanners - PII anonymization
llm_guard/input_scanners/anonymize.py - NER mappings
llm_guard/input_scanners/anonymize_helpers/ner_mapping.py - PII regex patterns
llm_guard/input_scanners/anonymize_helpers/regex_patterns.py - Prompt checks
llm_guard/input_scanners - Competitor blocking
llm_guard/input_scanners/ban_competitors.py - Topic blocking
llm_guard/input_scanners/ban_topics.py - Code detection
llm_guard/input_scanners/code.py - Emotion detection
llm_guard/input_scanners/emotion_detection.py - Injection detection
llm_guard/input_scanners/prompt_injection.py - Toxicity detection
llm_guard/input_scanners/toxicity.py
Response security
- Output scanner catalog
llm_guard/output_scanners - Response checks
llm_guard/output_scanners - Relevance check
llm_guard/output_scanners/relevance.py
Model support
- Model configuration
llm_guard/model.py - Model loading helpers
llm_guard/transformers_helpers.py
HTTP API
- Analyze and scan routes
llm_guard_api/app/app.py - Scanner orchestration
llm_guard_api/app/scanner.py - API configuration
llm_guard_api/app/config.py
Other components
- Application caller
- API caller
Connections 26
- Application caller → Evaluate workflow: submits text
README.md - Evaluate workflow → Input scanner contract: scans prompts
llm_guard/evaluate.py - Evaluate workflow → Output scanner contract: scans responses
llm_guard/evaluate.py - Input scanner catalog → PII anonymization: exports scanner
llm_guard/input_scanners/__init__.py - Input scanner catalog → Competitor blocking: exports scanner
llm_guard/input_scanners/__init__.py - Input scanner catalog → Topic blocking: exports scanner
llm_guard/input_scanners/__init__.py - Input scanner catalog → Code detection: exports scanner
llm_guard/input_scanners/__init__.py - Input scanner catalog → Emotion detection: exports scanner
llm_guard/input_scanners/__init__.py - Input scanner catalog → Injection detection: exports scanner
llm_guard/input_scanners/__init__.py - Input scanner catalog → Toxicity detection: exports scanner
llm_guard/input_scanners/__init__.py - PII anonymization → NER mappings: uses mappings
llm_guard/input_scanners/anonymize.py - PII anonymization → PII regex patterns: uses patterns
llm_guard/input_scanners/anonymize.py - PII anonymization → Placeholder vault: stores placeholders
llm_guard/input_scanners/anonymize.py - NER mappings → Model configuration: configures models
llm_guard/input_scanners/anonymize_helpers/ner_mapping.py - Output scanner catalog → Relevance check: exports scanner
llm_guard/output_scanners/relevance.py - Output scanner catalog → Response checks: exports scanners
- Response checks → Placeholder vault: supports deanonymization
README.md - Relevance check → Model configuration: uses configuration
llm_guard/output_scanners/relevance.py - Relevance check → Model loading helpers: loads model
llm_guard/output_scanners/relevance.py - Model configuration → Model loading helpers: provides model settings
llm_guard/transformers_helpers.py - API caller → Analyze and scan routes: sends requests
llm_guard_api/app/app.py - Analyze and scan routes → Scanner orchestration: loads and runs scanners
llm_guard_api/app/app.py - Analyze and scan routes → API configuration: uses configuration
llm_guard_api/app/app.py - Scanner orchestration → Input scanner catalog: loads prompt scanners
llm_guard_api/app/scanner.py - Scanner orchestration → Output scanner catalog: loads response scanners
llm_guard_api/app/scanner.py - Scanner orchestration → Placeholder vault: shares vault
llm_guard_api/app/scanner.py