Service policies for AI securables
This feature is in Beta. Workspace admins can control access to this feature from the Previews page by opting into the Unity Gateway Service Policies preview. See Manage workspace-level previews.
Service policies let you govern the content of interactions with AI services registered in Unity Catalog, including external MCP servers and models from any provider, not just Databricks-hosted ones. Unity Catalog grants determine whether a principal can call a service. Service policies govern how that interaction proceeds, based on the content of the request and response and on who is making the call.
Service policies are the mechanisms you use to implement guardrails for AI services. If you're looking to add guardrails, such as blocking sensitive data, prompt injection, or unsafe content, service policies are the mechanism: Databricks has built-in guardrails for common risks, you can write custom policies for rules specific to your organization, and you can enforce a third-party guardrail vendor's decisions with an external service policy.
This matters most when agents act on behalf of users. An agent inherits everything the user can access, and services often reach external systems. Service policies let you set guardrails on that activity. For example, you can require user consent before an agent pushes code to a Git repository through an MCP Service, deny a model response that contains personally identifiable information (PII), or block unsafe content.
Custom policies can also check and enforce the presence or absence of caller-supplied request tags. See Require an eligible project and the request tags reference.
Service policies are one of three kinds of attribute-based access control (ABAC) policy in Unity Catalog:
- ABAC GRANT policies grant Unity Catalog privileges on securables whose governed tags match a condition. They control whether a principal can reach an object.
- Row filter and column mask policies control which rows and columns a principal sees in a table.
- Service policies govern the content of each request and response to an AI service, to allow or deny it. On an MCP Service, a policy can also hold an input request for approval.
ABAC GRANT policies are access control. Row filter and column mask policies and service policies are content policies, which govern what happens after a principal has access. Like a row filter or column mask, a custom SQL service policy references a Unity Catalog function that contains the governance logic and attaches it to a securable.
How service policies complement Unity Catalog grants
Unity Catalog privileges and service policies address different governance questions and operate at different enforcement points.
Aspect | Unity Catalog privileges | Service policies |
|---|---|---|
Question answered | Can this principal call this service? | How must this interaction proceed? |
Inputs | Principal identity and granted privileges | Request content, response content, request tags, tool annotations, and actor context |
Enforcement point | Before the request reaches the service | Before the service is invoked (input phase, ON CALL) and after the service responds (output phase, ON RESULT) |
Granularity | Per principal, per securable | Per request, based on content and context |
Service policies don't replace Unity Catalog grants. A principal must first have the appropriate Unity Catalog privileges to call a service. Service policies then evaluate the content of each interaction to enforce additional governance rules.
Policy decisions
A service policy evaluates the content of a request or response and returns one of three outcomes:
- ALLOW: the interaction proceeds.
- DENY: the policy blocks the interaction. For chat-style model APIs, instead of an error status, Databricks returns a successful (HTTP 200) response. On a Model Service or Model Provider Service, the assistant turn carries a short message naming the service policy that blocked, and a top-level
databricks_service_policyobject carries the structured detail, including the blockreason. Returning the block as a normal turn keeps conversational clients that resend the full history, such as coding agents, from re-triggering the same block on every later turn. An embedding input denial returns HTTP 400 and blocks the whole request before the model runs. On an MCP Service, the response is a JSON-RPC error with the blockreasoninerror.message. - ASK: on an MCP Service, the policy pauses a request for user approval before the tool runs. Use this action when a user must approve a sensitive operation, such as a destructive MCP tool call. For external agents calling an MCP Service, the approval prompt is delivered through MCP URL-mode elicitation. If a custom policy function returns
ASKfor a Model Service or Model Provider Service, Databricks blocks the request or response because these services cannot ask the user for approval. See Return a decision.
A custom policy is either a SQL user-defined function (UDF) that receives the interaction event (which includes the actor and the request or response content) and returns a decision result, or an LLM-as-a-judge policy that classifies the content against criteria you write in natural language. Built-in policies are managed by Databricks, and an external service policy sends the content to a third-party guardrail service that returns the decision.
A custom policy can also be a Python UDF.
Evaluation points
Databricks evaluates service policies at the following points for MCP tool calls and supported model API requests:
- Input (ON CALL): Before Databricks invokes the service, against the request. Use this phase to inspect requests before they reach the underlying service. For example, block a request that invokes a destructive MCP tool, or deny a prompt that contains sensitive data before it reaches a model.
- Output (ON RESULT): After the service responds, against the response. Use this phase to inspect responses before they return to the caller. For example, block a response that contains hallucinated content or sensitive data.
Embedding requests support the input phase only. No policy evaluates the resulting vectors.
On model services and model provider services, output policies can check a streaming response as it's generated and release approved text before the model finishes. See Streaming responses.
For chat-style model APIs and MCP tool calls, a custom policy function runs at both points. It inspects the current phase (event:type) and decides how to act, so a single policy can govern the request, the response, or both. To act on only one phase, branch on event:type in the function body. For built-in policies and custom LLM-as-a-judge policies, you choose the phase in the policy form's Phase setting instead. Some built-in policies support different phases on different services. The Jailbreak guardrail runs only on the input phase on model and model provider services, and on input, output, or both on MCP services. The policy form preselects output for Jailbreak on an MCP service, but API callers must explicitly set the policy's options.phases request field to pre_call (input), post_call (output), or pre_call,post_call (both). Hallucination detection runs only on the output phase. External service policies are also scoped by phase: you choose the input phase, the output phase, or both when you attach one.
Order of evaluation
You can attach more than one service policy to a service. Each attachment has a rank (priority), and a DENY at one rank stops evaluation at later ranks. Databricks evaluates ranks in ascending order on the input phase (ON CALL, lowest rank first) and in the reverse order on the output phase (ON RESULT). Policies at the same rank are evaluated in two stages, as described below. Use different ranks to control evaluation order.
Evaluation within a rank
For chat-style model APIs and MCP tool calls, Databricks evaluates policies at the same rank in two stages:
- Blocking LLM-as-a-judge policies run in parallel. These are the built-in and custom LLM-as-a-judge policies that block (
DENY) content, such as unsafe-content detection. Because they are the model-backed checks, running them concurrently means their added latency is roughly that of the slowest single evaluation, not their sum. - The remaining policies then run sequentially, but only if no policy in the first stage returned
DENY. This stage covers custom policy functions, external service policies, thesystem.ai.detect_sensitive_databuilt-in policy, and policies that pause for approval (ASK), including an LLM-as-a-judge policy set to ask instead of block. Their order within this stage is undefined.ASKpauses an input call only for MCP Services. For Model Services and Model Provider Services,ASKblocks the request or response.
A DENY in the parallel stage skips the sequential stage. The sequential stage doesn't stop at a DENY: every policy in it runs, even after one returns DENY. For example, a custom SQL policy that denies a request doesn't stop an external service policy at the same rank from sending the content to its vendor. A DENY in either stage stops evaluation at later ranks, so to skip a policy when another one denies, put the denying policy at a rank that's evaluated first.
For embedding requests, blocking judges at the same rank run one at a time, with up to four input items checked concurrently. A judge DENY skips the remaining policies at that rank. See Embedding input guardrails for the effect on judge calls and latency.
The following diagram shows where the two phases sit around a service and what each decision does:

To see the policies attached to a specific service and the order they run in, open the service's Policies tab and click See execution flow.
Streaming responses (Beta)
Streaming evaluation is in Beta. It's part of the Unity Gateway Service Policies preview and has no separate toggle. See Manage workspace-level previews.
On model services and model provider services, each policy has a Response evaluation setting that controls how output policies handle streaming requests:
- Streaming evaluation: The default. Output policies check the response as the model generates it, and Databricks releases approved text before the model finishes.
- Full response evaluation: Output policies evaluate the complete response before any of it is released.
Existing policies also use streaming evaluation by default. Select Full response evaluation when no text can reach the client before the whole response passes, or when a custom policy requires the complete answer or final fields such as token usage.
If any output policy that applies to a request uses full response evaluation, including a policy in Log mode, every output policy evaluates the complete response. For chat-style requests, custom SQL and Python policies run on both phases, so their setting also counts. With streaming evaluation, those functions run on each window even if their logic only acts on the request. The setting has no effect on input-only policies.
Streaming evaluation applies to streaming requests to the supported chat-style model APIs. Output policies use full response evaluation for non-streaming chat-style requests and MCP tool results. In the API, set a policy's stream_mode field to STREAM_MODE_WINDOWED_SYNC for streaming evaluation or STREAM_MODE_FULLY_BUFFERED for full response evaluation. Omitting the field selects streaming evaluation. MCP services reject the field.
How streaming evaluation works
With streaming evaluation, Databricks holds the model's output and checks it in overlapping windows:
- With the default settings, Databricks runs the output policies after a few hundred new characters arrive. If the stream is slower, the next chunk after about a second can also trigger a check. Only one check runs at a time per request.
- Each check rereads recent response text, typically the last 16,000 characters, and all unreleased text if that's longer. The overlap gives policies context from earlier windows, rather than only the newest text.
- When a window passes, Databricks releases approved text, typically retaining a short tail until a later check or stream completion. This reduces the chance of releasing part of a sensitive value before the policy recognizes the complete value.
- At completion, Databricks evaluates any remaining output or changed completion metadata, such as token usage when available. From the first client tool call onward, the rest of the response waits for final approval.
- If a policy denies the response, Databricks withholds unreleased text, adds a message that says a service policy blocked the response, and ends the stream. Text already released stays with the client.
The following example shows overlapping checks with a held tail.

Text reaches the client in bursts rather than token by token because each release waits for the policies to finish. The held tail reduces boundary risks but doesn't guarantee that sensitive content can't reach the client.
Built-in service policies
Databricks provides built-in service policies under the system.ai namespace. These cover common governance scenarios without custom SQL. The Databricks AI guardrails are built-in service policies: preconfigured, Databricks-managed policies (such as unsafe-content and jailbreak detection) that you attach the same way as a custom policy:
system.ai.block_unsafe_content: denies interactions that contain unsafe or harmful content.system.ai.block_jailbreak: detects jailbreak and prompt-injection content. On Model Services and Model Provider Services, it evaluates model input only. On MCP Services, it can evaluate the tool call and arguments on input, the tool result on output, or both.system.ai.block_hallucination: denies responses that contain hallucinated content.system.ai.detect_sensitive_data: detects structured sensitive data (such as credit card numbers and Social Security numbers) and either denies the interaction or masks the matched values. Unlike the others, it's deterministic (pattern-based, no evaluator model) and can mask rather than only deny. See Detect sensitive data with a service policy.
To use a built-in policy, attach it to a service. You need MANAGE on the target service.
The built-in policies are Databricks-managed and don't appear as functions you can browse in the system.ai schema in Catalog Explorer. You select and attach them by name through the Unity Gateway UI, as described in Create and attach a service policy.
How built-in service policies work
The built-in service policies come in two kinds. The LLM-as-a-judge built-ins each run a Databricks-curated prompt against an evaluator model to decide whether the content violates the policy. Sensitive Data Detection is deterministic: it matches patterns and checksums, and it doesn't use an evaluator model.
The evaluator model service
Each built-in service policy runs its prompt on an evaluator model service, the model that judges the content. Databricks preselects a default evaluator, so no setup is required. To use a different model, expand Advanced options when you attach the policy and select one. You need EXECUTE on the model service you choose, plus USE CATALOG and USE SCHEMA on its catalog and schema. See Grant access to a model service. Databricks checks this access when you attach the policy, so callers of the protected service don't need access to the evaluator. The evaluator is separate from the service you're protecting, so a policy can judge a request to one model service using a different model as the evaluator.
Databricks maintains the policy's prompt, which is read-only. You can view it under Prompt when you attach the policy to see the exact criteria the evaluator applies.
What the evaluator receives
When a built-in service policy runs, Databricks sends the evaluator a request with two parts:
- A system message that contains the policy prompt and an output contract (described in the following section).
- A user message that contains the content under evaluation. On the input phase, it's the latest user message on a model or model provider service, together with a window of recent conversation turns (see below), or the tool call and its arguments on an MCP service. On the output phase, it's the model's reply or the MCP tool result after the tool has run.
The evaluator receives serialized text rather than decoded image or audio payloads. On the output phase and on MCP services, it judges only that single extracted item. For Jailbreak output evaluation on an MCP service, the input includes both result.content and result.structuredContent, including inline text and textual resource blobs. Other LLM judges on MCP services receive result.content only. On the input phase, LLM judges on MCP services skip tool calls that have no arguments.
Jailbreak on an MCP service extracts resource blobs the same way as Sensitive Data Detection. Decoding is best effort: blobs that can't be decoded or that exceed the size limit are omitted. Screening uses the media type (mimeType) that the MCP server declares. A missing or empty media type is treated as text, and blobs declared as nontextual are excluded. The evaluator doesn't fetch resource links.
Jailbreak on an MCP service screens tool calls (tools/call) and their results. Tool descriptions returned by tools/list are not screened.
For embedding input, each evaluator call receives one nonblank item.
On the input phase of chat-style model APIs, the evaluator also receives a window of recent conversation turns, so it can catch patterns that build up across a conversation, such as gradual escalation. When you create a policy in the policy form, the Conversation window defaults to the last 10 turns. You can change the number, set it to 1 to judge only the latest message, or select Evaluate the entire conversation. A policy that has no conversation window set judges only the latest message.
Output contract
Databricks automatically appends a JSON output contract to the policy prompt, so the evaluator returns a structured decision instead of free text. The evaluator returns:
flagged(boolean):trueif the content violates the policy's criteria.confidence(float,0.0to1.0, optional): the evaluator's confidence in the decision.reason(string): a short explanation of why the content was flagged. Returned whenflaggedistrue.
When the evaluator returns flagged: true, Databricks blocks the interaction by default. On an MCP service, a policy configured to ask instead pauses the request for human approval before the tool runs. Because Databricks applies the contract for you, the LLM-as-a-judge built-ins need no configuration beyond the phase and rank. Sensitive Data Detection also takes classification tags and an action.
An OpenJev evaluator doesn't use this contract. It answers a flag-or-allow question instead and returns no reason. See Use OpenJev as the evaluator.
The evaluator is a model, so its verdicts are non-deterministic, and the reason is short free text rather than structured data. To see which policies ran on a request and what each decided, use the unified trace table. To also see a judge's confidence and the exact content it judged, enable an inference table on the evaluator model service. See Debug and audit a policy decision.
Evaluation cost
During Beta, Databricks doesn't charge a separate fee for built-in service policies. Each evaluation is billed like any other call to the evaluator model service, so the cost depends on how that model is served. The tokens billed for each evaluation cover the policy prompt, the output contract, the extracted message, and the evaluator's response. To limit overhead, keep the number of policies per phase small and prefer a low-latency evaluator model.
With streaming evaluation, an output judge evaluates overlapping response text several times. Each evaluation makes a separate call to the evaluator model service and consumes evaluator tokens. A long streamed response can therefore use more evaluator tokens than one full-response evaluation.
External service policies
An external service policy enforces the decisions of a third-party guardrail vendor, such as an AI security or data-loss-prevention service. You attach it with the External guardrail type and point it at a Unity Catalog HTTP connection that stores the vendor's endpoint and OAuth machine-to-machine credentials. On each evaluation, Databricks sends the content under evaluation to the vendor, which returns a verdict with an optional reason, and Databricks enforces the result.
The vendor must implement the Databricks external policy API. External service policies return ALLOW or DENY, or ASK to hold an MCP tool call for user approval. They can't redact content. They fail closed, so an unreachable or slow vendor endpoint denies the call. See Enforce a partner guardrail with an external service policy.
With streaming evaluation, an external output policy calls the vendor for each evaluated window. These calls count against the vendor's rate limits and pricing.
Supported services
You can attach service policies to the following Unity Catalog service securables:
- MCP Services: managed, external, and custom MCP servers.
- Model Services: hosted and external LLM endpoints.
- Model Provider Services: governed external model providers.
Supported model APIs
On Model Services and Model Provider Services, service policies support these chat-style model APIs on the input and output phases:
- Chat completions: Databricks, OpenAI, and Cursor.
- Anthropic Messages.
- OpenAI Responses and Databricks Open Responses, including Codex requests routed through these formats.
- Gemini
generateContentandstreamGenerateContent.
Service policies also support embedding inputs in mlflow/v1/embeddings and openai/v1/embeddings requests. See Embedding input guardrails.
With any service policy attached, including one in Log mode, unmanaged passthrough requests return HTTP 400.
For supported chat-style APIs, request a single response (n=1 or candidateCount=1). Requests for multiple responses return HTTP 400 when any policy is attached, including one in Log mode.
Service policies do not run on legacy text completion or System One inference requests. Neither the input phase nor the output phase runs, even when a policy is attached to the service. This limitation applies to all policy types, including Sensitive Data Detection, LLM-as-a-judge, custom SQL or Python, and external policies. Use a supported model API for requests that require policy enforcement.
A successful response from an unsupported API does not mean that a policy evaluated the request or response.
Embedding input guardrails
Service policies support mlflow/v1/embeddings and openai/v1/embeddings requests to Model Services and Model Provider Services.
Text guardrails accept an input string or a nonempty array of strings. Enforcing text guardrails reject token-ID arrays, mixed or nested arrays, missing or null input, and empty arrays. With an enforcing text guardrail, a batch can contain at most 16 items. Larger batches return HTTP 400 before the embedding model runs. The embedding API and model still apply their text, token, and request-size limits.
The following text policies support the input phase (pre_call):
- Sensitive Data Detection, with Deny or Mask.
- Unsafe-content and jailbreak detection, with Deny.
- Custom LLM-as-a-judge policies, with Deny.
For embeddings, service policies evaluate only the input. On a service that accepts both chat and embedding requests, a policy configured for both phases evaluates embedding input and still evaluates chat output. Output-only policies and hallucination detection are unsupported for embeddings. For example, an enforcing hallucination policy or an output-only Mask policy on a Model Provider Service rejects embedding requests with HTTP 400 before the model runs. To allow embedding requests, choose one of the following options:
- Route embeddings through a separate service to preserve chat enforcement.
- Replace the policy with one that supports the input phase. If you add the input phase to an existing policy, it also starts checking chat input.
- Switch the policy to Log mode. This also stops enforcement for chat requests.
An LLM-as-a-judge policy evaluates each nonblank item separately, regardless of its conversation-window or max_turns setting. Each judge makes one call per nonblank item, so a 16-item batch with two judges makes up to 32 judge calls, adding latency and usage costs. If a judge cannot accept the full item, the request fails with POLICY_EVALUATION_FAILED in the error reason. The text is not truncated. If any item is denied, the whole request fails with HTTP 400.
With Mask, Sensitive Data Detection replaces matches within each item while preserving item order and other request fields, such as model and dimensions. The model embeds the redacted text, so vectors and retrieval results can change. The embedding response does not indicate whether or which items were redacted.
For consistent retrieval, apply the same redaction policy to indexed content and query text. If your application must know whether an input changed, redact the text before calling the embeddings API. To judge redacted text, give the redaction policy a lower input rank than the judge. Log mode leaves the input unchanged.
Custom SQL and Python policies receive only the embedding request event. External policies receive a model_call event when configured for input. Neither type receives embedding results. A custom function that acts only on response events does not protect embedding requests. Each input event contains the whole request JSON. Embeddings have no conversation message. See External service policy API reference.
Fail-closed behavior
Service policy evaluation fails closed for MCP tool calls and supported model API requests. Requests to the excluded model APIs skip policy evaluation, so they don't fail closed. When you attach a policy through the Unity Gateway, Databricks validates it at attach time, and any error during evaluation results in DENY. Errors include user errors in the policy function, system errors, missing fields in the request context, and timeouts. For an external service policy, errors also include a vendor endpoint that is unreachable, returns an error, or returns a verdict other than ALLOW, DENY, or ASK.
A misconfigured or broken policy blocks the interaction rather than allowing it through.
If an enforcing output policy fails during streaming evaluation, the stream can end with an error instead of a policy block message. Failures include evaluator errors, timeouts, and rate-limit errors. The client keeps any text already released. If a custom policy needs the complete response to evaluate successfully, select Full response evaluation.
A policy in Log mode is non-enforcing. It records what the policy would have decided without blocking the interaction, so even a would-be DENY lets the request proceed. Request validation still applies, including request-tag validation.
Limitations
The following limitations apply:
- Embedding policies: Service policies support only the input phase for embeddings. See Embedding input guardrails.
- Model API coverage: Coverage depends on the model API. See Supported model APIs.
- Transformation: Service policies return a decision (ALLOW, DENY, or ASK) and don't transform request or response content. The one exception is the built-in
system.ai.detect_sensitive_datapolicy, which can redact matched values on model services. - External service policies: An external service policy returns
ALLOWorDENY, orASKon an MCP tool call, and supports OAuth machine-to-machine authentication only. See External service policy limitations. - Supported services: Service policies apply to MCP Services, Model Services, and Model Provider Services. Agent Services are not supported.
- Model provider service passthrough: On a model provider service, Databricks rejects unmanaged passthrough requests with HTTP 400 when any policy is attached, including a policy in Log mode. Without an attached policy, Forward all URL paths forwards these requests to the provider. Policies evaluate only the provider's supported API paths.
- Conversation window: Built-in and custom LLM judges can use a conversation window only during input evaluation on model and model provider services. For those judges, output evaluation and MCP services use a single message, tool call, or tool result. For chat-style model APIs, custom SQL and Python functions receive a provider-neutral object under
event:context.conversationduring both input and output evaluation. During output evaluation, the object contains the originating request's conversation. See How built-in service policies work and Conversation context. Embedding judges evaluate each nonblank item independently, and embedding events have no conversation context. - Streaming responses: Released text can't be recalled after a denial or evaluation error. Each check, including the final check, uses a bounded lookback, so a long response might never be evaluated in full by a single check. See How streaming evaluation works.
- Nested evaluation: If the evaluator model service you select for a built-in service policy has its own policies attached, Databricks skips them when running the evaluation. This prevents recursion.
- Custom Python policies: Custom Python policies are available only in some regions and have additional limitations. See Python policy limitations.