Skip to content

Prebuilt Middleware

Railtracks ships a suite of prebuilt middleware so you can add common behavior to an agent without writing it yourself. Every item below is a normal middleware; you attach it exactly like your own, on the middleware= (node) or model_middleware= (model) slot. For the difference between the two slots, see Middleware Overview; to build your own, see Custom Middleware.

The Slot column tells you where each middleware can be attached:

  • Node: wraps the whole node/function call (middleware=).
  • Model: wraps a single model call (model_middleware=).
  • Both: slot-agnostic; works in either.

Catalog

Middleware Slot What it does
Lock Both Serialize concurrent invocations that share the same middleware instance.
Retry Both Re-run the wrapped call when it raises a transient error, with a configurable backoff.
Timeout Both Cancel the wrapped call and raise TimeoutError when it exceeds a deadline.
MaxCalls Both Raise MaxCallsExceededError once the wrapped call has been invoked a set number of times.
ContextInjection Model Fill {placeholder} templates in the prompt from the active session context.

Guardrails

Guardrails are model middleware too; a policy layer that inspects inputs and outputs and can allow, transform, or block them. See the Guardrails overview for the full picture; the prebuilt rails are catalogued here.

Guardrail Slot What it does
BlockTextInputGuard / BlockTextOutputGuard Model Block an interaction when a regex pattern matches the input or output.
InputLengthGuard / OutputLengthGuard Model Block an interaction when the character count exceeds a ceiling.
PIIRedactInputGuard / PIIRedactOutputGuard Model Redact PII (emails, phone numbers, custom patterns, …) from inputs and outputs.

Verifiers

pre_verifier and post_verifier are node middleware for gating a call before or after it runs — the basis for human-in-the-loop workflows in Railtracks. They aren't catalogued in the table above since there are only two, tightly coupled by design; see the Verifiers overview for the full picture.

Note

Don't see what you are looking for? Create your own middleware for a custom solution, or contribute a prebuilt middleware so others can reuse it.