What you will be able to do
- Match each kind of malicious input (direct and indirect prompt injection, jailbreaks, data exfiltration) to the guardrail that counters it
- Choose between the built-in Jailbreak guardrail, Sensitive Data Detection with block or redact, a custom LLM-as-a-judge policy and a custom SQL policy
- Write an LLM-as-a-judge policy prompt and roll it out safely in Log mode
- Predict which guardrail fires first when several are stacked on one model service
Key concept
Service policy (guardrail) — On Databricks, a guardrail is a service policy attached to an AI service in Unity Catalog. It reads the content of each request or response and returns a decision that allows or denies the interaction. Built-in, custom LLM-as-a-judge, custom SQL and external vendor checks all use this one mechanism.
1.Malicious inputs and the guardrail that counters each
A malicious input is text written to make a model do something its owner never intended. There are four common kinds. Jailbreaks try to talk the model out of its safety instructions. Direct prompt injection puts override instructions straight into the user's message. Indirect prompt injection hides those instructions in content the application pulls in, such as a tool result. Data exfiltration attempts try to get sensitive data or a dangerous link into the model's answer. The stakes go up when an agent is involved, because it acts with the user's permissions and often reaches outside systems.
On Databricks, each of these is handled by a service policy attached to the model service (or MCP service) that the application calls. A Model Service fronts a model, whether Databricks-hosted or from an external provider. An MCP Service fronts an external MCP server: an agent's tool calls pass through it, so it has its own input phase, which inspects the tool-call arguments, and its own output phase, which inspects the tool result. Unity Catalog grants decide whether a caller can reach the service at all. A service policy then reads the content of every interaction. Policies run at the input phase (ON CALL) before the service is invoked, or at the output phase (ON RESULT) after it responds. The full mechanics are in Guardrail phases (input/output) and outcomes. For this topic, two points matter. Defences against malicious input belong on the input phase. And a blocked call is not an error: the caller gets an HTTP 200 response whose assistant turn names the blocking policy, and a databricks_service_policy object carries the reason.
| Threat | Where it shows up | Guardrail that counters it |
|---|---|---|
| Jailbreak / direct prompt injection | The user's request | Built-in Jailbreak (system.ai.block_jailbreak), input phase only |
| Jailbreak spread over several turns | Recent conversation, not just the latest message | LLM-judge with the Conversation window widened (input phase) |
| Indirect injection via a tool | Tool result returned through an MCP Service | Output-phase policy on the MCP Service (custom LLM-as-a-judge or external) |
| Exfiltration of structured PII | Request or model response | Sensitive Data Detection (system.ai.detect_sensitive_data), block or redact |
| Exfiltration through a link | Model response | Custom SQL policy branching on event:type = 'response' |
| Org-specific forbidden topic | The user's request | Custom SQL rule (exact match) or custom LLM-as-a-judge (semantic) |
Exfiltration defences point the other way: they inspect the response on its way out. One example is a custom SQL policy that denies any response containing an http:// URL or a javascript: URI. Because it checks event:type for 'response', a user who only mentions those schemes in a question is not blocked. Sensitive Data Detection does the same job for structured identifiers such as Social Security and credit card numbers, on either phase.
Checkpoint 1 of 8· Match them up
Match each malicious-input threat to the guardrail that counters it
Tap a term, then the definition that fits it.
Jailbreak detection only inspects requests, so instructions injected through a tool result need their own policy on the MCP Service's output phase. Structured identifiers are caught by the pattern-based Sensitive Data Detection. Insecure links are caught by a SQL rule that only checks responses, so a user who just mentions those schemes is not blocked.
“Jailbreak (system.ai.block_jailbreak): denies prompt-injection and jailbreak attempts (requests only).”Source: docs.databricks.com
2.Choosing built-ins: Jailbreak, and block versus redact
Start with a built-in guardrail whenever one covers the risk. A built-in needs no code: you pick it by name, set its phase and rank, and attach it. The background on how these managed checks and their LLM judge work is in Built-in guardrails and their judge. For malicious input, the relevant built-in is Jailbreak (system.ai.block_jailbreak). It denies prompt-injection and jailbreak attempts, and it runs only on requests. Unsafe Content is a different check: it blocks harmful or violent material, not override attempts, so it does not replace Jailbreak.
A judge can only rule on what it is given. On a model service, an input-phase judge evaluates a Conversation window of recent messages, 10 by default. Set the window to 1 to judge only the latest message, or choose Evaluate the entire conversation. The window counts messages of any role, including tool messages. That matters because some jailbreaks only show up across an exchange, where the latest message looks harmless but the recent conversation is not. Multi-turn evaluation is limited, though: it works only on the input phase of Model Services and Model Provider Services, not on the output phase and not on MCP Services. A tool result is first produced as the MCP Service's response, and only output-phase policies on that service inspect it; Jailbreak, being input-only, does not run there. A tool message can later turn up in the window of a model request, but by then the text has already been returned to the agent. The defence against indirect injection therefore has to sit on the MCP Service's output phase.
Sensitive Data Detection is the deterministic built-in. It matches patterns, uses no evaluator model, adds well under 50 ms, and asks you to choose an action for each match. Block denies the whole interaction, and the reason names the categories it found, for example Detected sensitive data (US_SSN, CREDIT_CARD). Redact swaps each matched value for a placeholder token such as [US_SSN] and passes the rewritten request on to the model. Redact is the action exam questions sometimes call "sanitize". The two actions are tuned differently. Blocking is tuned for precision, so a random string of digits does not deny a request. Redaction is tuned for recall, because a missed value is worse than an over-redaction.
Checkpoint 2 of 8· Check yourself
Customers of a support assistant on a Model Service sometimes paste their Social Security number into a question. The assistant must still answer them, but the model must never see the real number. Which guardrail configuration meets both requirements?
Redact replaces each matched value with a placeholder and forwards the rewritten request, so the model can still answer without seeing the SSN. Block denies the whole interaction, so the customer gets no answer. Log mode passes the request through untouched. Unsafe Content looks for harmful language, not identifiers.
“Redact (all services): Databricks replaces each matched value with a placeholder token, such as [US_SSN], and forwards the rewritten content.”Source: docs.databricks.com
Checkpoint 3 of 8· Exam question
A healthcare intake assistant must never process a request that contains a patient's social security number: any such request should be rejected outright rather than forwarded to the model in a modified form. Which guardrail configuration meets this requirement?
Correct answer: A — A PII guardrail set to the block action, returning an error for a request with a detected SSN rather than sending it to the model.
- A. The PII check detects the SSN, and the block action rejects the whole request with an error. The request is never sent to the model in original or modified form, which is the behavior the intake assistant needs.
- B. The sanitize action masks the SSN but still passes the request on to the model. The requirement is outright rejection rather than forwarding a modified request, so this fails even though the SSN itself is hidden.
- C. Log mode only records detections and enforces nothing. The request containing the SSN would still reach the model unchanged, so nothing is rejected.
- D. A content-safety guardrail screens for violent or hateful language, not personally identifiable information. A request containing only an SSN would not be flagged, so it would still be forwarded to the model.
3.Writing a custom LLM-as-a-judge policy
Choose between the two kinds of custom policy by asking whether an exact rule can express the check. A custom SQL policy is a Unity Catalog function. It takes (event VARIANT), reads the message text from event:context.message, and returns ALLOW, DENY or ASK with a reason. It wins when the check is deterministic: a fixed codename, a tool name or argument, or who is calling. A custom LLM-as-a-judge policy wins when the rule is about meaning. "Is this user trying to get the assistant to reveal its instructions?" or "Is this request off topic?" has no keyword list. Any keyword filter for it is either easy to rephrase around or blocks legitimate users.
CREATE OR REPLACE FUNCTION main.governance.block_confidential_codename(
event VARIANT
)
RETURNS VARIANT
LANGUAGE SQL
RETURN
CASE
WHEN event:type::string = 'request'
AND contains(lower(event:context.message::string), 'project aurora')
THEN to_variant_object(named_struct('result', 'DENY', 'reason', 'Requests about confidential projects are not permitted.'))
ELSE to_variant_object(named_struct('result', 'ALLOW', 'reason', ''))
END;A judge policy is attached from the service's Policies tab. Set Guardrail type to Custom, Implementation to LLM-as-a-judge, choose a phase and an evaluator model service, and write a Prompt. The prompt says what to flag and what to leave alone. Leave out ALLOW, DENY and any output format. Databricks appends its own structured output contract, so the evaluator returns a JSON verdict, and a flagged verdict blocks the interaction. A good prompt states the scope ("may only help with the company's products, orders, billing, and account support") and gives concrete flag cases. It also names explicit exceptions so genuine questions pass. A custom SQL function runs at both phases and branches on event:type. A judge policy is scoped with the Phase setting instead.
Do not rebuild what a built-in already does. For jailbreak and prompt-injection detection, Databricks recommends the built-in Jailbreak guardrail with its default evaluator. Write a custom judge for the threats that are specific to your organisation. Examples are an injected instruction inside an MCP tool result, an attempt to pull a competitor's pricing out of a sales assistant, or personal names that pattern-based detection cannot recognise.
Because the evaluator is a model, its verdicts are non-deterministic, so a new judge should not start by blocking traffic. Under Advanced options, set Mode to Log. The policy then evaluates real requests and records what it would have decided, but it neither blocks nor rewrites anything. Review those would-be verdicts in the trace table, tune the prompt, and switch to blocking once the false positives are under control. The same applies to a new jailbreak guardrail. Changing the phase or the action does not give you this dry run. Moving the guardrail to the output phase judges something else entirely, and redact still changes traffic.
Checkpoint 4 of 8· Check yourself
A team wants its customer-support assistant to stay on topic, but users ask for coding help, essays and other unrelated tasks in many different phrasings. Which requirement is a better fit for a custom LLM-as-a-judge policy than for a custom SQL function?
Whether a message is off topic depends on what it means, and no keyword list captures that, so an LLM judge is the right tool. A fixed codename, a tool name or argument, and the identity of the caller are deterministic checks, and a SQL function handles those better.
“Semantic rules that you can describe in plain language, such as keeping an assistant on topic.”Source: docs.databricks.com
Checkpoint 5 of 8· Check yourself
A newly written judge policy must be tried on real traffic before it is allowed to affect any user. What configuration gives that dry run?
Log mode evaluates real interactions and records the decision the policy would have made, without blocking or rewriting anything. Moving the judge to the output phase means it judges different content, redact still changes traffic, and narrowing the window still blocks.
“Databricks recommends starting in Log mode and reviewing the would-be verdicts in the unified trace table.”Source: docs.databricks.com
Checkpoint 6 of 8· Exam question
Before rolling out a new jailbreak-protection guardrail to production traffic, a platform team wants to observe which real user requests it would flag without actually blocking or altering any traffic yet. Which guardrail setting accomplishes this?
Correct answer: A — Switch the guardrail to log mode, which evaluates requests in a dry-run state and writes the results to the logs, with no block or sanitize step.
- A. Log mode is the dry-run setting: the guardrail still evaluates incoming requests and records what it would flag, but applies no block or sanitize action. The team can therefore review real flagged requests while traffic stays untouched.
- B. Sanitize is an enforcement action. It rewrites the flagged text in the live request before the model sees it, so production traffic is altered, which the team wants to avoid during observation.
- C. Restricting the guardrail to the output phase moves evaluation from user requests to model responses. It still enforces its action on what it flags, so it neither shows which requests would be flagged nor leaves traffic untouched.
- D. The character limit only controls how much text the custom guardrail's evaluator reads. Whatever it does flag is still acted on, so lowering the limit gives no observation-only behavior and leaves traffic open to blocking or rewriting.
4.Stacking guardrails so the right one fires first
A secure model service usually has several policies, and their order decides what runs and what is skipped. The general rules are in Stacking guardrails: rank, short-circuit, latency. In short: on the input phase, ranks run in ascending order, and a DENY at one rank stops every later rank. Within a single rank, there is a second layer of ordering, and that is where people slip.
Within a rank, evaluation has two stages. First, the blocking LLM-as-a-judge policies (built-in Jailbreak and Unsafe Content, and custom judges set to block) run in parallel. Their combined latency is roughly that of the slowest single judge. Second, and only if none of them denied, the remaining policies run in sequence: custom SQL, external vendor policies, system.ai.detect_sensitive_data, and anything set to ASK. That sequential stage does not stop at its own first DENY. If a SQL policy denies a request, an external policy at the same rank still sends the content to its vendor.
Use rank, not attachment order, to put cheap deterministic checks first. If a codename rule or Sensitive Data Detection sits at a lower rank than the judges, it runs before any evaluator model is called. A deterministic DENY then stops the expensive judges and any vendor call at later ranks. Lower-rank redaction also means a later judge only sees text that is already redacted, so its prompt should tell it to ignore placeholders such as [US_SSN]. For a fail-closed posture, rely on how a model service treats ASK. It cannot pause for user approval, so a custom SQL or Python policy that returns ASK there blocks the request or response.
Both policies are in the same rank's sequential stage, and that stage keeps running after a DENY. The vendor still receives the denied prompt. Move the SQL policy to a lower rank, such as 5. Its DENY then stops evaluation before rank 10 runs.
Checkpoint 7 of 8· Put it in order
No policy denies this request. In what order does Databricks evaluate the input-phase policies on this model service?
- 1.Sensitive Data Detection set to redact, at rank 5
- 2.A custom SQL codename policy at rank 10
- 3.Jailbreak and a custom judge set to block, both at rank 10, running in parallel
- 4.An external DLP vendor policy at rank 20
On the input phase, ranks run from lowest to highest, so the rank-5 redaction runs first and the later judges see only redacted text. Within rank 10, the blocking LLM judges run first and in parallel. The SQL policy runs after them in the sequential stage, and only if no judge denied. The rank-20 vendor policy runs last.
“The remaining policies then run sequentially, but only if no policy in the first stage returned DENY.”Source: docs.databricks.com
Checkpoint 8 of 8· Exam question
An endpoint has both a PII redaction guardrail and a jailbreak-protection guardrail configured on the input phase, alongside a sanitizing step. A request contains no personal data but does contain an obfuscated instruction-override attempt. Based on the guardrail execution model, what happens?
Correct answer: A — The PII and jailbreak guardrails run in parallel on the input, the jailbreak guardrail triggers, and the request is rejected before sanitizing runs.
- A. Blocking guardrails within a phase run in parallel. The jailbreak guardrail triggers on the obfuscated override attempt, so the request is rejected without the sanitizing step executing, whatever the PII guardrail finds.
- B. Sanitizing runs only after the blocking guardrails have passed the request. It does not run before them, so it cannot rewrite the obfuscated text first. A triggering jailbreak guardrail rejects the request before sanitizing is reached.
- C. Blocking guardrails in the same phase are evaluated in parallel, not one at a time in the order they were added. The PII guardrail does not have to finish before the jailbreak guardrail starts, so this describes the wrong execution model.
- D. Both guardrails are configured on the input phase, which evaluates the request before the model sees it. The jailbreak guardrail therefore triggers there and rejects the request, so it never reaches the model or the sanitizing step.
Sources
(5)
Every claim above is drawn from one of these pages, quoted as it was written on the date shown.
- 1.
“An agent inherits everything the user can access, and services often reach external systems.”
↩︎ Malicious inputs and the guardrail that counters each“Instead of an error status, Databricks returns a successful (HTTP 200) response.”
↩︎ Malicious inputs and the guardrail that counters each“The remaining policies then run sequentially, but only if no policy in the first stage returned DENY.”
↩︎ Stacking guardrails so the right one fires first“a DENY at one rank stops evaluation of all later ranks”
↩︎ Stacking guardrails so the right one fires first“If a custom SQL or Python policy returns ASK for a Model Service or Model Provider Service, Databricks blocks the request or response”
↩︎ Stacking guardrails so the right one fires first“If you're looking to add guardrails, such as blocking PII, prompt injection, or unsafe content, service policies are the mechanism”
↩︎ Key concept“The sequential stage doesn't stop at a DENY: every policy in it runs, even after one returns DENY.”
↩︎ Exam trap 3“jailbreak detection runs only on the input phase and hallucination detection only on the output phase”
↩︎ Prediction“A DENY in the parallel stage skips the sequential stage.”
↩︎ Prediction - 2.
“so a user who merely mentions those schemes in a prompt doesn't trip it on the way in”
↩︎ Malicious inputs and the guardrail that counters each“A model service can front a Databricks-hosted model or an external provider such as OpenAI, Anthropic, or Google”
↩︎ Malicious inputs and the guardrail that counters each“Jailbreak (system.ai.block_jailbreak): denies prompt-injection and jailbreak attempts (requests only).”
↩︎ Choosing built-ins: Jailbreak, and block versus redact“Jailbreak (system.ai.block_jailbreak): denies prompt-injection and jailbreak attempts (requests only).”
↩︎ Exam trap 1“Jailbreak (system.ai.block_jailbreak): denies prompt-injection and jailbreak attempts (requests only).”
↩︎ Checkpoint - 3.https://docs.databricks.com/aws/en/data-governance/unity-catalog/service-policies/detect-sensitive-dataOfficial docs
“On an MCP service, the input phase inspects the tool-call arguments and the output phase inspects the tool result.”
↩︎ Malicious inputs and the guardrail that counters each“On an MCP service, the input phase inspects the tool-call arguments and the output phase inspects the tool result.”
↩︎ Choosing built-ins: Jailbreak, and block versus redact“Block (all services): Databricks denies the interaction.”
↩︎ Choosing built-ins: Jailbreak, and block versus redact“Redaction should catch as much sensitive data as possible, since a missed value is worse than an over-redaction”
↩︎ Choosing built-ins: Jailbreak, and block versus redact“Add the LLM judge at a higher rank so it evaluates the already-redacted content.”
↩︎ Stacking guardrails so the right one fires first“Redact (all services): Databricks replaces each matched value with a placeholder token, such as [US_SSN], and forwards the rewritten content.”
↩︎ Exam trap 2“Redact (all services): Databricks replaces each matched value with a placeholder token, such as [US_SSN], and forwards the rewritten content.”
↩︎ Checkpoint - 4.https://docs.databricks.com/aws/en/data-governance/unity-catalog/service-policies/policy-examplesOfficial docs
“The Conversation window counts individual messages of any role (system, user, assistant, and tool), not back-and-forth pairs”
↩︎ Choosing built-ins: Jailbreak, and block versus redact“Some risks are only visible across an exchange, when the latest message looks fine but the recent conversation doesn't.”
↩︎ Choosing built-ins: Jailbreak, and block versus redact“It isn't available on the output phase or on MCP Services.”
↩︎ Choosing built-ins: Jailbreak, and block versus redact“For jailbreak and prompt-injection detection, use the built-in Jailbreak guardrail with its default evaluator instead of OpenJev.”
↩︎ Writing a custom LLM-as-a-judge policy - 5.https://docs.databricks.com/aws/en/data-governance/unity-catalog/service-policies/create-service-policyOfficial docs
“use a custom LLM-as-a-judge policy, or a SQL function when the rule must be deterministic or depends on who is calling”
↩︎ Writing a custom LLM-as-a-judge policy“Use it for semantic checks that a deterministic rule can't express”
↩︎ Writing a custom LLM-as-a-judge policy“Don't write ALLOW or DENY in the prompt, and don't specify an output format.”
↩︎ Writing a custom LLM-as-a-judge policy“The evaluator is a model, so its verdicts are non-deterministic. Databricks recommends starting in Log mode”
↩︎ Writing a custom LLM-as-a-judge policy“To record verdicts without blocking, set Mode to Log.”
↩︎ Exam trap 4“Semantic rules that you can describe in plain language, such as keeping an assistant on topic.”
↩︎ Checkpoint“Databricks recommends starting in Log mode and reviewing the would-be verdicts in the unified trace table.”
↩︎ Checkpoint