#1597·guardrails

1.0.0: delete on_fail — unary validate raises, streaming always emits uniformly-typed spans

Author: zsimjeeCreated Jul 24, 2026Updated Sep 23, 2026
LabelsStale

Target: 1.0.0. on_fail is deleted outright. Validation splits into two paths, and guardrails never mutates and never resolves — it judges, and the caller decides.

Revises guardrails-ai/guardrails-ai#11. Related: #1592 (reask), questions 5 and 6 in #1591.

Path 1 — unary validate: returns or raises

guard.validate(value) returns the value on success. On failure it raises, and the exception carries:

  • the original value
  • the fix value, if one was produced
  • the reask request, if one is constructible
  • the per-validator judgments (reasons, error spans)

Reask stops being a policy and becomes a derived artifact — the exception carries it whenever one can be built, because it costs nothing to include. This also makes FIX_REASK unnecessary: it existed because the library had to choose between fixing and reasking, and now the caller gets both and picks.

Path 2 — streaming: always noop, uniformly-typed spans

The guard emits one result per span. It never fixes in place, never raises, never filters. Every span carries the same fields, and the caller branches:

python
for span in guard.stream(resp):
    if span.validation_passed:
        out.write(span.value)
    elif span.fix_value is not None:
        out.write(span.fix_value)       # accept the suggested fix
    else:
        break                            # or raise, or drop the span

This works because the caller is the emitter. The guard hands the span to the caller, not to the end user, so the caller still has the choice — which is exactly what fix-in-place was doing implicitly on their behalf.

What this buys

  • on_fail disappears completely, in both paths. Nothing behavioral is persisted in guard config, so stored configs and hub templates become inert validator lists. This also removes the forward-compat hazard where a new on_fail value silently changes the behavior of a safety control on an older SDK.
  • One streaming code path. run_validators_stream_fix and run_validators_stream_noop collapse into one. The coarse dispatch in run_validators_stream (fix variant if any validator has FIX) goes away, and with it the "what if v1=fix and v2=raise" precedence question.
  • One result shape, used twice. The span type and the exception payload become the same class: value, original, fix_value, validation_passed, summaries/spans. That is a genuinely teachable API.
  • Structured streaming parity gets much cheaper. There is no fix/filter/refrain to port — the structured path just emits judgments per parsed fragment, so the guard clause at run_validators:328–354 is deleted rather than reimplemented. Largely resolves question 6 in #1591.

multi_merge survives — as a suggestion, not an application

Worth being explicit, since it's the most differentiated machinery in the package: when several validators each fix the same span, the guard still three-way merges their fixes against the original (multi_merge) and offers the result as span.fix_value. The merge logic is kept; only its application moves to the caller.

This matters because the caller cannot reasonably merge multiple validators' fixes themselves. Exposing per-validator fixes and expecting the caller to reconcile them would be a real capability loss; exposing one merged suggestion is not.

The one real cost: accumulator drift

This needs a conscious decision.

In fix-in-place, acc_output and validator_partial_acc reset after each emitted span, so subsequent validation proceeds from the text that was actually emitted (the fixed text). Under always-noop the guard does not know what the caller chose. So a validator whose granularity spans multiple emitted spans — whole-text chunking, or anything checking coherence across a document — judges the model's stream while the caller is emitting a modified stream. The judgments drift from what the end user actually sees.

This is the streaming form of the drift concern that opened #1448, inverted. Options:

  1. Accept and document it: validators judge the model's output, not your edited output. Defensible — arguably that is what you want, since you are validating the model.
  2. Feedback channel: make the stream a generator you .send() the accepted value into, so validators continue from what was emitted. Correct, but unusual DX and awkward to type.
  3. Restrict: validators needing cross-span context are unsupported in streaming.

Recommendation: option 1, stated plainly in the docs rather than left to be discovered.

DX regression, and the sugar that fixes it

Today for chunk in guard(...): print(chunk.validated_output) works with fixes silently applied. Now every streaming caller writes an if/else. Mitigation: a small helper implementing the obvious policy — e.g. guardrails.autofix(guard.stream(resp)) yielding plain strings — shipped outside the core, same pattern as the retry helper in #1592. Core stays mechanism; sugar is separate and opt-in.

Compatibility

  • OnFailAction is deleted, not shrunk. Every stored guard config and hub template carries onFail (e.g. server_ci/guard-template.json). Decide whether unknown/legacy on_fail keys are ignored with a warning or hard-error with a migration message. Today an unrecognized value falls through Validator.__init__ into the CUSTOM branch and dies in _set_on_fail_method on inspect.getfullargspec with an inscrutable TypeError — that is fail-closed but unhelpful.
  • custom was the maintainer's documented answer to the request in #1448. Its migration path becomes try/except in unary mode, or an if/else per span in streaming. Defensible, but say it in the release notes.
  • Every hub validator's constructor takes on_fail=.... Deleting the parameter is an ABI change across the fleet; accepting-and-ignoring it with a DeprecationWarning for one major is probably necessary.

Source: guardrails-ai/guardrails