A safety filter blocks or restricts model responses in configured harmful-content categories. In a production LLM application, it is one part of a broader guardrail system: an automated circuit breaker intended to keep harmful or policy-violating content from reaching users. section 13.3.1
Place protection at more than one point in the request path. Input guards screen or sanitize queries before generation; processing controls monitor generation; output guards validate responses before delivery. If a malicious input passes the first layer, the output layer can still catch a violation. section 13.3.1
Configure each layer for a distinct failure mode:
- Set model safety thresholds by harmful-content category. The illustrated settings block harassment and hate speech at low-and-above thresholds, and dangerous content at medium-and-above. section 13.3.1
- Validate inputs with Guardrails AI. The example raises an exception for competitor mentions but fixes detected email addresses, credit-card numbers, and Social Security numbers. section 13.3.1
- Use prompt constraints to define scope and sensitive-information boundaries, but retain validation around the model rather than relying on prompt instructions alone. section 13.1.1 section 13.3.1
A public-facing documentation assistant
A retrieval-augmented assistant accepts user questions and generates answers from documentation. Its input guard can redact an email address or reject a prohibited competitor mention before the query reaches the LLM. Model safety settings restrict specified harmful-content categories, while an output guard checks the answer before delivery. section 2.1.7 section 13.3.1
safety_settings = [
types.SafetySetting(
category=types.HarmCategory.HARM_CATEGORY_HARASSMENT,
threshold=types.HarmBlockThreshold.BLOCK_LOW_AND_ABOVE,
),
types.SafetySetting(
category=types.HarmCategory.HARM_CATEGORY_HATE_SPEECH,
threshold=types.HarmBlockThreshold.BLOCK_LOW_AND_ABOVE,
),
types.SafetySetting(
category=types.HarmCategory.HARM_CATEGORY_DANGEROUS_CONTENT,
threshold=types.HarmBlockThreshold.BLOCK_MEDIUM_AND_ABOVE,
),
]
The safety-settings listing shows the separate category and blocking threshold configured for each model-level filter. section 13.3.1













