Adding guardrails that stop an LLM from producing harmful output
LLM guardrails are input/output controls layered around a model to reduce risks like toxic content, prompt injection, PII leakage, and off-topic or hallucinated responses. In Databricks-based GenAI applications, guardrails are typically implemented as code (validation, filtering, moderation logic) within the application layer that wraps calls to the LLM, and can also draw on safety filtering capabilities offered by some serving/model endpoints. Guardrails should be applied both to user input before it reaches the model and to model output before it reaches the user.
1 · Learn the must-know
- Guardrails can be implemented at multiple points: input validation/filtering, prompt-level instructions constraining scope and behavior, and output validation/filtering before returning a response to the user.
- Common guardrail techniques include keyword/regex or classifier-based content filtering, PII detection and redaction, allow/deny topic lists, and structured output validation (e.g., checking JSON schema conformance).
- Prompt engineering itself is a guardrail technique: system prompts can instruct the model to refuse out-of-scope requests, avoid speculation, and cite only provided context to reduce hallucination.
- Guardrails are distinct from and complementary to evaluation: evaluation measures quality/safety after the fact (offline or via monitoring), while guardrails actively block or modify problematic content in real time.
- Because a single guardrail technique is rarely sufficient, a layered/defense-in-depth approach combining input checks, prompt design, and output checks is recommended to reduce negative outcomes like harmful, biased, or off-brand responses.
- Guardrail logic should be treated as part of the application code and tested/versioned like any other component, since overly restrictive guardrails can cause false refusals while overly loose ones fail to prevent negative outcomes.
2 · Check your understanding
A Generative AI Engineer is deploying a customer-facing chatbot on Mosaic AI Model Serving. During testing, the chatbot occasionally generated offensive language when provoked by adversarial prompts. The engineer needs to block such responses before they reach the end user, without retraining the underlying model. Which approach should the engineer use?
What you have tried across Databricks GenAI Engineer's objectives, not a readiness score.
Design Applications10.71% of the exam*0 of 6 tried
Data Preparation14.29% of the exam*0 of 8 tried
Application Development23.21% of the exam*0 of 13 tried
Assembling and Deploying Applications26.79% of the exam*0 of 15 tried
Governance7.14% of the exam*0 of 4 tried
Evaluation and Monitoring17.86% of the exam*0 of 10 tried
* Our estimate. Databricks publishes no section weights.
3 · Keep going
Ready for more? Take a weighted mock or try free practice questions.