CertSafari
    Databricks Certified Generative AI Engineer Associate· Lessons

    Domain 5 · Lesson 44/56

    Guardrails against prompt injection, jailbreaks and data exfiltration

    Select guardrail techniques to protect against malicious user inputs to a Gen AI application

    17 min read
    2% of exam
    5 sources
    Published 22 Oct 2026
    Docs as of 17 Oct 2026

    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.

    Which guardrail technique counters which threat
    ThreatWhere it shows upGuardrail that counters it
    Jailbreak / direct prompt injectionThe user's requestBuilt-in Jailbreak (system.ai.block_jailbreak), input phase only
    Jailbreak spread over several turnsRecent conversation, not just the latest messageLLM-judge with the Conversation window widened (input phase)
    Indirect injection via a toolTool result returned through an MCP ServiceOutput-phase policy on the MCP Service (custom LLM-as-a-judge or external)
    Exfiltration of structured PIIRequest or model responseSensitive Data Detection (system.ai.detect_sensitive_data), block or redact
    Exfiltration through a linkModel responseCustom SQL policy branching on event:type = 'response'
    Org-specific forbidden topicThe user's requestCustom 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.

    Sources123

    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?

    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?

    Sources243

    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.

    A deterministic input-phase rule: exact matching is all this check needs, so SQL beats a judgesql
    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?

    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?

    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?

    Sources54

    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.

    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. 1.Sensitive Data Detection set to redact, at rank 5
    2. 2.A custom SQL codename policy at rank 10
    3. 3.Jailbreak and a custom judge set to block, both at rank 10, running in parallel
    4. 4.An external DLP vendor policy at rank 20

    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?

    Sources13

    Sources

    (5)

    Every claim above is drawn from one of these pages, quoted as it was written on the date shown.

    1. 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. 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. 3.
      “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. 4.
      “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. 5.
      “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

    Spotted a mistake, or was something unclear? Tell us.