nvidia/add-middleware
Add a new guardrail or intercept type to the NeMo Relay middleware pipeline
npx skills add https://github.com/NVIDIA/NeMo-Relay --skill add-middleware
Use karpathy-guidelines alongside this skill for implementation or review
work. Keep changes scoped, surface assumptions, and define focused validation
before editing.
NeMo Relay supports guardrails (validate/gate) and intercepts (transform) at various
pipeline stages. Adding a new middleware type requires changes across all layers.
Use this skill when introducing a new middleware registration surface or adding
middleware behavior to a new pipeline stage.
Decide these before editing code:
execution intercept?
final response output?
middleware runs?
data, category_profile, andmetadata can change, and is the event used only as immutable context?
Refer to docs/about-nemo-relay/concepts/middleware.mdx for the full diagrams.
conditional guardrails -> request intercepts -> sanitize request (for events)
| execution intercept chain(callable) -> sanitize response
conditional guardrails -> request intercepts -> sanitize request (for events)
| execution intercept chain(callable) -> sanitize response
specialized tool or LLM sanitizer (when applicable) -> mark or scope event
sanitizer -> subscriber and exporter dispatch
crates/core/src/api/runtime/callbacks.rs.
pub type MyNewFn = Box<dyn Fn(&str, Json) -> Json + Send + Sync>;
NemoRelayContextState incrates/core/src/api/runtime/state.rs.
Add a SortedRegistry<GuardrailEntry<MyNewFn>> or SortedRegistry<Intercept<MyNewFn>>
field to the state struct.
crates/core/src/api/.Use the existing global_*_registry_api! and scope_*_registry_api! macro
patterns in crates/core/src/api/registry.rs. Both global and scope-local
variants are needed unless the design explicitly rules one out.
NemoRelayContextState incrates/core/src/api/runtime/state.rs.
Follow the pattern of tool_sanitize_request_chain or tool_request_intercepts_chain.
Update the relevant lifecycle owner to call the new chain method at the
appropriate pipeline stage. Tool and LLM paths live in
crates/core/src/api/tool.rs and crates/core/src/api/llm.rs; shared mark and
scope event sanitization lives in crates/core/src/api/shared.rs and is called
from crates/core/src/api/scope.rs.
Follow the add-binding-feature skill for the cross-binding implementation checklist.
crates/core/src/api/tool.rs, crates/core/src/api/llm.rscrates/core/src/api/runtime/callbacks.rscrates/core/src/api/runtime/state.rscrates/core/src/context/registries.rscrates/core/src/registry.rsdocs/about-nemo-relay/concepts/middleware.mdxdocs/about-nemo-relay/architecture.mdxdocs/instrument-applications/advanced-guide.mdxvalidate-changeTake nvidia/add-middleware from the repository into ~/.claude/skills for personal
use, or into .claude/skills inside a project.
The agent identifies a skill by the name field in its header. Two skills with the
same name cannot sit side by side — one of them will be ignored.