Skip to main content

OnFailActions for Validators

Guardrails provides a number of OnFailActions for when a validator fails. The OnFailAction specifies the corrective action that should be taken if the quality criteria is not met. The corrective action can be one of the following:

ActionBehavior
OnFailAction.REASKReask the LLM to generate an output that meets the correctness criteria specified in the validator. The prompt used for reasking contains information about which quality criteria failed, which is auto-generated by the validator.
OnFailAction.FIXProgrammatically fix the generated output to meet the correctness criteria when possible. E.g. the formatter provenance_llm validator will remove any sentences that are estimated to be hallucinated.
OnFailAction.FILTER(Only applicable for structured data validation) Filter the incorrect value. This only filters the field that fails, and will return the rest of the generated output.
OnFailAction.REFRAINRefrain from returning an output. This is useful when the generated output is not safe to return, in which case a None value is returned instead.
OnFailAction.NOOPDo nothing. The failure will still be recorded in the logs, but no corrective action will be taken.
OnFailAction.EXCEPTIONRaise an exception when validation fails.
OnFailAction.FIX_REASKFirst, fix the generated output deterministically, and then rerun validation with the deterministically fixed output. If validation fails, then perform reasking.