liveBook · Manning

Guardrail

As explained in Machine Learning Platform Engineering

A safety filter is a model-level mechanism that blocks or restricts generated content belonging to configured harmful-content categories.

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

How Machine Learning Platform Engineering covers it

How deep it goes
Shows layered placement, Guardrails AI input validation, and model harm-category thresholds; does not detail the filters’ internal classification.
Examples
Uses category-specific blocking thresholds, email redaction, competitor-mention rejection, and a guarded documentation assistant.
What it assumes
Assumes an LLM application and introduces guardrail placement through its request path.
What you can do after
Apply it via Guardrails AI validators and configure model harm-category thresholds within a layered LLM request path.
How it connects
Connects safety filtering to input sanitization, PII detection, output validation, prompt constraints, and adversarial testing.

Also explained in

Compare how 14 books explain guardrail →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Machine Learning Platform Engineering. The section links point to the parts of the book it draws on.