High severity beginner · Fix: 2-5 min

ValueError

guardrails.guard.ValueError: Invalid on_fail action

What this error means
Guardrails Guard.use() received an invalid on_fail action parameter that is not one of the allowed handler types ('exception', 'filter', 'fix', 'fix_repeat', 'noop').

Stack trace

traceback
Traceback (most recent call last):
  File "<your_script>.py", line 42, in <module>
    guard.use(ToxicLanguage, on_fail='skip')
  File "<guardrails_install>/guard.py", line 287, in use
    raise ValueError(f"Invalid on_fail action '{on_fail}'. Allowed actions: {', '.join(ALLOWED_ON_FAIL_ACTIONS)}")
ValueError: Invalid on_fail action 'skip'. Allowed actions: exception, filter, fix, fix_repeat, noop
QUICK FIX
Change on_fail parameter to one of: 'exception', 'filter', 'fix', 'fix_repeat', or 'noop': check for typos and verify you're on guardrails-ai>=0.5.0.

Why it happens

Guardrails defines a strict set of valid on_fail handlers that determine what happens when a validator fails. The on_fail parameter must be one of: 'exception' (raise error), 'filter' (remove failing output), 'fix' (attempt auto-correction), 'fix_repeat' (retry fix until valid), or 'noop' (silent pass). Passing a misspelled, deprecated, or unsupported action name causes this ValueError at Guard initialization time.

Detection

Review all Guard().use() calls in your codebase and validate on_fail parameter values against the official allowed list. Add type hints (Literal['exception'|'filter'|'fix'|'fix_repeat'|'noop']) to catch this at IDE time before runtime.

Causes & fixes

1

Typo in on_fail parameter name (e.g., 'skip' instead of 'noop', 'error' instead of 'exception')

✓ Fix

Change on_fail parameter to one of: 'exception', 'filter', 'fix', 'fix_repeat', or 'noop'. Double-check spelling.

2

Using deprecated on_fail action from guardrails-ai v0.3 or earlier

✓ Fix

Upgrade to guardrails-ai>=0.5.0 and map old actions: 'fix_repeat' replaces old 'auto_fix', 'noop' replaces old 'silent'.

3

Passing a callable or custom handler instead of a string action name

✓ Fix

Use string literals only: on_fail='exception'. Custom error handlers use exception catching, not on_fail parameter.

4

on_fail parameter is None, empty string, or non-string type

✓ Fix

Ensure on_fail is a non-empty string literal matching one of the five allowed actions. Use Literal type hints to enforce at IDE time.

Code: broken vs fixed

Broken - triggers the error
python
import os
from guardrails import Guard
from guardrails.hub import ToxicLanguage

guard = Guard()
# BUG: 'skip' is not a valid on_fail action
guard.use(ToxicLanguage, on_fail='skip')

result = guard.validate('This is a test')
print(result)
Fixed - works correctly
python
import os
from guardrails import Guard
from guardrails.hub import ToxicLanguage

guard = Guard()
# FIXED: Use valid on_fail action 'noop' (silent pass) or 'exception' (raise error)
guard.use(ToxicLanguage, on_fail='exception')

result = guard.validate('This is a test')
print(f'Validation result: {result}')
Changed on_fail from invalid 'skip' to valid 'exception', which raises an error if validation fails — allowing your code to handle failures explicitly with try/except.

Workaround

Wrap Guard.use() in a try/except block and provide a fallback on_fail='noop' if the intended action is unsupported in your version. Log the exact on_fail action you intended so you can debug the version mismatch later.

Prevention

Use type hints with Literal to enforce valid on_fail values at IDE time: from typing import Literal; guard.use(validator, on_fail: Literal['exception', 'filter', 'fix', 'fix_repeat', 'noop'] = 'exception'). Validate guardrails-ai version in CI/CD pipelines to catch deprecated action deprecations before deployment.

Python 3.9+ · guardrails-ai >=0.5.0 · tested on 0.5.x
Verified 2026-04
Verify ↗

Community Notes

No notes yetBe the first to share a version-specific fix or tip.