Output Filtering After Generation
What you'll learn: How to catch and block inappropriate LLM outputs after generation but before reaching users.
The Last Line of Defense
Even when your LLM has been fine-tuned, aligned with RLHF, and the input has been filtered, models can still generate harmful, biased, or off-policy content. Output filtering acts as your safety net — analyzing what the model produces and blocking problematic responses before users see them.
Think of it like a quality control inspector at the end of a production line. The product (LLM output) has already been manufactured, but you check it one final time before shipping.
Why Output Filtering Matters
Input filtering (covered previously) stops bad prompts from reaching your model. But users can craft clever prompts that bypass input filters, or the model might hallucinate unsafe content from benign inputs. Output filtering gives you a second chance to enforce safety policies.
How It Works
After your LLM generates a response:
- Pass the output through moderation APIs or custom classifiers
- Check against policy rules: hate speech, PII leakage, medical advice, competitor mentions, etc.
- Score risk levels using thresholds
- Block or replace problematic outputs with safe fallback messages
- Log incidents for monitoring and model improvement
You might check for toxicity scores, regex patterns for sensitive data, or semantic similarity to banned content templates.
Trade-offs
Output filtering adds latency (typically 50-200ms) and can produce false positives. Balance strictness with user experience — overly aggressive filtering frustrates users, while loose filtering risks harm.
Key Takeaway: Output filtering is your final safety checkpoint, catching harmful LLM responses after generation but before users see them, complementing input filtering and model training to create defense-in-depth for content moderation.