Interceptor examples
The Interceptors SDK repository ships a catalog of example interceptors in aidial_interceptors_sdk/examples/. They run as a single DIAL service, so you can register them with DIAL Core and try interception against a real deployment without writing any code first.
They are reference implementations, not production-ready services — treat them as something to read and adapt.
Running the examples
Install the SDK with the examples extra and start the server:
pip install uvicorn python-dotenv "aidial-interceptors-sdk[examples]"
echo "DIAL_URL=<YOUR_DIAL_CORE_URL>" > .env
uvicorn "aidial_interceptors_sdk.examples.app:app" --host "0.0.0.0" --port 5000 --env-file ./.env
Every example is exposed at its own deployment endpoint, following the usual DIAL pattern:
http://localhost:5000/openai/deployments/<deployment-name>/chat/completionshttp://localhost:5000/openai/deployments/<deployment-name>/embeddings
The README gives the deployment name for each example.
To put one in front of a model, register it in DIAL Core and assign it — see Configure and assign interceptors.
What the examples demonstrate
The examples fall into a handful of patterns — the shapes an interceptor can take:
- Redact and restore. Replace sensitive content before the model sees it, then put the original values back on the way out. The most involved pattern, since it has to keep state between the request and the response.
- Reject. Inspect the request and refuse it outright when it breaks a rule, without ever calling the model.
- Rewrite. Alter the prompt in flight and pass it on. The smallest interceptors take this shape, which makes them the best first read.
- Observe. Report usage, traces, or metrics to an external system while leaving the payload untouched.
- Transform attachments. Act on files travelling with the request or response rather than on the text.
- Reshape the stream. Cache a response, buffer or re-chunk it, or call the upstream more than once. Fan-out is the one pattern that overrides
call_upstreams— see Overriding behaviour. - Transform embeddings. Modify the input text or the returned vectors.
- Pass through. Change nothing, to verify the chain is wired correctly.
Chat completion examples live in examples/chat_completion/, embeddings ones in examples/embeddings/. The SDK README lists each one with its dependencies and configuration.
Further reading
- Tutorial: PII-redacting interceptor — build your own version of the anonymizer example
- Interceptors SDK integration reference — the callbacks these examples override
- Configure and assign interceptors — register an interceptor with DIAL Core
- Guardrails — what interceptor-based guardrails enforce and where they apply