Expand description
Core vocabulary and execution engine for Wardline.
Wardline evaluates guardrails inline and synchronously, in the caller’s request path: a check returns a blocking verdict before an action is taken or an LLM response is released. No queue, no separate service, no async runtime — a blocked action never happens rather than being detected shortly after it did.
| Type | Role |
|---|---|
Guard | One check. The trait you implement. |
Verdict | What a guard decided: allow, block, or modify. |
GuardError | Why a guard reached no decision at all. |
FailPolicy | What the pipeline does about that failure. |
Context | Per-request metadata and the deadline. |
Deadline | A cooperative wall-clock bound. |
Pipeline | An ordered list of guards, run in place. |
Trace | The bounded record of what each guard did. |
Metrics | Optional per-guard counters (allow/block/error/panic). |
The key distinction: Verdict::Block means the guard said no;
GuardError means it said nothing. Failures are resolved by the
failing guard’s own FailPolicy, which defaults to
FailPolicy::FailClosed, so a broken guard doesn’t silently stop
guarding.
Pipeline::evaluate runs guards in order, stops at the first block, and
returns the decision together with its Trace — so a caller can log
why something was refused, not just that it was. A panic inside a guard
becomes GuardError::Panicked and is resolved through that guard’s
FailPolicy; it never unwinds past the caller.
Enable the tracing feature to emit a wardline.evaluate span and a
wardline.guard span per check, including an error event when a guard
panics. Without that feature this crate still depends on nothing outside
std. See AGENTS.md for the architectural invariants.
§Example
use wardline_core::{Context, Guard, GuardError, Verdict};
struct NoProfanity;
impl Guard for NoProfanity {
type Input = str;
type Output = ();
fn check(&self, input: &str, _ctx: &Context) -> Result<Verdict, GuardError> {
if input.contains("darn") {
return Ok(Verdict::block("profanity detected"));
}
Ok(Verdict::Allow)
}
fn name(&self) -> &'static str {
"no_profanity"
}
}
let ctx = Context::new();
assert_eq!(NoProfanity.check("hello there", &ctx), Ok(Verdict::Allow));
assert!(NoProfanity.check("well darn", &ctx).is_ok_and(|v| v.is_block()));Structs§
- Context
- Everything a guard knows about the request beyond the input itself.
- Deadline
- A point in time by which work is expected to be finished.
- Guard
Counters - Snapshot of one guard’s counters.
- InMemory
Metrics - A process-local
Metricssink, useful in tests and examples. - Pipeline
- An ordered list of guards, evaluated in place on the calling thread.
- Pipeline
Result - One evaluation: the decision, and the record of how it was reached.
- Trace
- Every guard the pipeline ran, in order, with a hard cap on entries.
- Trace
Entry - One guard’s line in the audit trail.
Enums§
- Fail
Policy - How the pipeline resolves a guard that errored, timed out, or panicked.
- Guard
Error - Something went wrong while evaluating a guard.
- Trace
Outcome - What one guard did, as recorded for the audit trail.
- Value
- A typed metadata value carried in a
Context. - Verdict
- The outcome of a single guard evaluation.