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:
| Category | Modifies | Example use case |
|---|---|---|
| Pre-interceptor | Incoming request only | Inject a system prompt, reject requests matching a blocklist |
| Post-interceptor | Outgoing response only | Stamp a watermark on generated images, collect streaming statistics |
| Generic interceptor | Both request and response | Anonymize 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:
| Level | Applies to | Defined in |
|---|---|---|
| Global | Every deployment in the DIAL instance | globalInterceptors array in DIAL Core config |
| Application type | All instances of a specific application type (e.g., all Quick Apps) | dial:applicationTypeInterceptors in the type schema |
| Local | A single model or application deployment | interceptors 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:
| SDK | Package | Purpose |
|---|---|---|
| DIAL SDK | aidial-sdk | Build applications and model adapters |
| Interceptors SDK | aidial-interceptors-sdk | Build 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