Use this guide when instrumentation is working and you want NeMo Relay to enforce policy, transform requests, wrap execution, or sanitize observability payloads around tool and LLM calls.
You will add middleware to an instrumented application and verify that it runs in the expected part of the pipeline:
Complete Instrument a Tool Call or Instrument an LLM Call. Middleware only runs when the call goes through a NeMo Relay managed lifecycle API.
Use this table to match the behavior you need with the correct middleware family.
Use the narrowest middleware type that matches the behavior. For example, do not use a request intercept when you only need to hide a secret from exported events.
This example adds three behaviors around a search tool:
api_key from emitted request events.Use scope-local middleware when a policy applies only to one request, tenant, experiment, or agent run.
Use global middleware for process-wide behavior, such as organization-wide redaction. Use scope-local middleware for request-specific policy, such as tenant routing or an A/B test.
NeMo Relay exposes the same core middleware families for tools and LLMs:
Sanitize guardrails affect only the payload recorded on emitted events. Request intercepts affect the real request that reaches the tool or provider. Execution intercepts wrap the callback itself and are only available when the invocation uses managed execution.
Scope-local variants are available through nemo_relay.scope_local.register_*, Node.js scopeRegister* helpers, and Rust scope_register_* functions.
Run one allowed request and one rejected request:
api_key values.Middleware runs by ascending priority inside each middleware family. Families and lifecycle emission run in this order for managed tool calls:
If a later middleware does not run, check whether an earlier conditional-execution guardrail rejected the call or a request intercept raised an error.
Check these symptoms first when the workflow does not behave as expected.
Use these links to continue from this workflow into the next related task.