Skip to main content

What are interceptors

Interceptors are middleware components that transform requests before they reach a model or application and transform responses before they reach the client. They enforce compliance, protect sensitive data, and add cross-cutting capabilities — without modifying the model or application code itself.

If you build applications with DIAL, interceptors let you apply policies like PII redaction, content filtering, or audit logging across any number of deployments from a single, reusable service.

Why interceptors exist​

Enterprise AI deployments share a set of recurring requirements that cut across every model and application:

  • Responsible AI — block requests that violate content policies or lead to biased responses.
  • Privacy and compliance — anonymize personally identifiable information (PII) before data reaches a model, then restore it in the response.
  • Audit and observability — log every request and response for compliance, debugging, or analytics.
  • Cost and performance — cache frequent requests to reduce latency and model invocation costs.
  • Content safety — reject prompts containing prohibited terms, detect prompt injection attempts, or filter harmful model output.

Implementing these concerns inside every application creates duplication and drift. Interceptors extract them into standalone services that DIAL Core orchestrates automatically.

Interceptor categories​

Interceptors fall into three categories based on which side of the request-response cycle they modify:

CategoryModifiesExample use case
Pre-interceptorIncoming request onlyInject a system prompt, reject requests matching a blocklist
Post-interceptorOutgoing response onlyStamp a watermark on generated images, collect streaming statistics
Generic interceptorBoth request and responseAnonymize PII in the request and restore it in the response, cache responses

A single interceptor service can implement any of these categories. The category is a design pattern, not a configuration setting — it depends on which callback methods the interceptor overrides.

How the interceptor chain works​

When a client sends a chat completion request, DIAL Core routes it through each configured interceptor in sequence before forwarding it to the target deployment. Responses travel back through the same chain in reverse order.

Request:   Client → Interceptor 1 → Interceptor 2 → Model/App
Response: Model/App → Interceptor 2 → Interceptor 1 → Client

Every hop in this diagram passes through DIAL Core. Core manages the chain using a reserved deployment name (interceptor) and per-request keys. Each interceptor calls the upstream through Core, which resolves the next interceptor (or the final deployment) transparently.

Scoping levels​

Interceptors can be applied at three levels. When all three are configured, they execute in this order:

LevelApplies toDefined in
GlobalEvery deployment in the DIAL instanceglobalInterceptors array in DIAL Core config
Application typeAll instances of a specific application type (e.g., all Quick Apps)dial:applicationTypeInterceptors in the type schema
LocalA single model or application deploymentinterceptors array on the deployment

Request order: Global → Application type → Local → Deployment

Response order: Deployment → Local → Application type → Global

Global interceptors have the strictest rules — they see the original request first and examine the final response last.

For configuration details, see Configure and assign interceptors.

Two SDKs​

DIAL provides two Python SDKs for different extension points:

SDKPackagePurpose
DIAL SDKaidial-sdkBuild applications and model adapters
Interceptors SDKaidial-interceptors-sdkBuild interceptors

The Interceptors SDK depends on the DIAL SDK internally — it uses DIALApp for serving and the DIAL SDK's request/response objects for context. But the programming model is different: applications implement ChatCompletion with full control over the response, while interceptors override specific callbacks to modify requests and responses flowing through the chain.

For how the SDK meets DIAL Core, see the SDK integration reference.

Demo​

Watch a short overview of interceptors in action:

Interceptors demo video