Skip to main content
on_fail actions are instructions to Guardrails that direct action when a validator fails. They are set at the validator level, not the guard level. The full set of on_fail actions are avialable in the Error remediation concepts doc, and will not all be covered here. Instead, this interactive doc will serve to guide you on how and when to use different on_fail actions.

Raise Exceptions

If you do not want to change the outputs of an LLM when validation fails, you can instead wrap your guard in a try/catch block. This works particularly well for input validation.

noop to log and continue

If you want to log the error and continue, you can use the noop action. This is useful for when you want to log the error, but not stop the LLM from running.

fix to automatically fix the error

Note, not all validators implement a ‘fix’ value. You can view the FailResult implementation in a validator to see if it has a fix value. Here’s an example that shows how Detect PII is written to return anonymized text as a fix value

reask to automatically ask for an output that passes validation

This reask prompt is computed from the validators themselves. It’s an interpolation In order for the reask prompt to work, the following additional params must be provided:
  • messages
  • llm_api OR model

custom to anything else