1.0.0: delete on_fail — unary validate raises, streaming always emits uniformly-typed spans
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:
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 spanThis 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_faildisappears 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 newon_failvalue silently changes the behavior of a safety control on an older SDK.- One streaming code path.
run_validators_stream_fixandrun_validators_stream_noopcollapse into one. The coarse dispatch inrun_validators_stream(fix variant if any validator hasFIX) goes away, and with it the "what ifv1=fixandv2=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–354is 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:
- 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.
- 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. - 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
OnFailActionis deleted, not shrunk. Every stored guard config and hub template carriesonFail(e.g.server_ci/guard-template.json). Decide whether unknown/legacyon_failkeys are ignored with a warning or hard-error with a migration message. Today an unrecognized value falls throughValidator.__init__into theCUSTOMbranch and dies in_set_on_fail_methodoninspect.getfullargspecwith an inscrutableTypeError— that is fail-closed but unhelpful.customwas 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 aDeprecationWarningfor one major is probably necessary.
Source: guardrails-ai/guardrails