High severity beginner · Fix: 2-5 min

InvalidInstallationError

guardrails.validators.InvalidInstallationError: hub install requires guardrails-ai>=0.5

What this error means
A Guardrails Hub validator requires guardrails-ai version 0.5.0 or later, but your installed version is older or incompatible with the validator's requirements.

Stack trace

traceback
Traceback (most recent call last):
  File "<your_script>.py", line X, in <module>
    from guardrails.hub import ToxicLanguage
  File "/path/to/site-packages/guardrails/hub/__init__.py", line YZ, in _load_validator
    raise InvalidInstallationError(
      'Hub validator "ToxicLanguage" requires guardrails-ai>=0.5.0 but found guardrails-ai==0.4.2'
    )
guardrails.validators.InvalidInstallationError: hub install requires guardrails-ai>=0.5.0
QUICK FIX
Upgrade guardrails-ai to version 0.5.0 or later: `pip install --upgrade 'guardrails-ai>=0.5.0'`

Why it happens

Guardrails Hub validators (ToxicLanguage, ValidJson, etc.) are versioned independently from the core guardrails-ai package. When you try to import a validator from the hub, it checks the installed guardrails-ai version against its minimum requirement. If your installed guardrails-ai is older than 0.5.0, the validator refuses to load because its code depends on APIs that only exist in guardrails-ai>=0.5.0. This typically happens when you upgrade validators without upgrading the core package, or when different packages in your environment have conflicting dependency pins.

Detection

Check your installed guardrails-ai version before importing hub validators: run `pip show guardrails-ai` and verify the version is >=0.5.0. Add a simple version check at the top of your script to fail fast with a clear message before validator import attempts.

Causes & fixes

1

Installed guardrails-ai version is older than 0.5.0 (e.g., 0.4.2 or 0.3.x)

✓ Fix

Upgrade guardrails-ai to the latest 0.5.x version: run `pip install --upgrade guardrails-ai>=0.5.0` and verify with `pip show guardrails-ai`

2

guardrails-ai is pinned to an old version in your requirements.txt or poetry.lock file

✓ Fix

Remove the pinned version constraint (e.g., change `guardrails-ai==0.4.2` to `guardrails-ai>=0.5.0`) in your requirements file, then run `pip install --upgrade -r requirements.txt`

3

A dependency of another package (e.g., in setup.py or pyproject.toml) pins guardrails-ai to <0.5.0, overriding your upgrade

✓ Fix

Run `pip show guardrails-ai` and check the dependency tree with `pipdeptree | grep guardrails`. Update the parent dependency constraint or use `pip install --upgrade --force-reinstall guardrails-ai>=0.5.0` to override

4

Poetry or pipenv lock file has stale guardrails-ai version locked in

✓ Fix

Run `poetry lock --no-update` then `poetry update guardrails-ai` (or `pipenv lock --clear && pipenv sync`) to refresh the lock with the latest compatible version

Code: broken vs fixed

Broken - triggers the error
python
import os
from guardrails.hub import ToxicLanguage  # ERROR: raises InvalidInstallationError if guardrails-ai<0.5

guard = Guard().use(ToxicLanguage, on_fail='exception')
result = guard.validate('This is a test')
print(result)
Fixed - works correctly
python
import os
import subprocess
import sys
from packaging import version

# FIX: Check guardrails-ai version before importing hub validators (guardrails-ai>=0.5 required)
try:
    import guardrails
    installed_version = guardrails.__version__
    required_version = '0.5.0'
    
    if version.parse(installed_version) < version.parse(required_version):
        print(f'ERROR: guardrails-ai {installed_version} is too old. Upgrading to >=0.5.0...')
        subprocess.check_call([sys.executable, '-m', 'pip', 'install', '--upgrade', 'guardrails-ai>=0.5.0'])
        print('Upgrade complete. Please re-run your script.')
        sys.exit(0)
except ImportError:
    subprocess.check_call([sys.executable, '-m', 'pip', 'install', 'guardrails-ai>=0.5.0'])
    print('Installation complete. Please re-run your script.')
    sys.exit(0)

from guardrails import Guard  # NOW safe to import
from guardrails.hub import ToxicLanguage

guard = Guard().use(ToxicLanguage, on_fail='exception')
result = guard.validate('This is a test')
print(f'Validation result: {result}')
Added a pre-import version check that compares the installed guardrails-ai against the minimum required version (0.5.0) and auto-upgrades if needed, preventing the InvalidInstallationError from ever being raised.

Workaround

If you cannot upgrade guardrails-ai immediately, avoid importing validators from the hub and write custom validators inline instead. Define a Pydantic model and use Guard.from_pydantic(your_model) instead of relying on hub validators. This keeps you on the old guardrails-ai version temporarily, but you lose validator updates and community validators. This is NOT recommended for production: upgrade guardrails-ai as soon as possible.

Prevention

Pin guardrails-ai to a known-good version in your requirements.txt or pyproject.toml (e.g., `guardrails-ai>=0.5.0,<1.0.0`), run `pip install --upgrade guardrails-ai` during your CI/CD setup step, and add a startup assertion in your application that checks the version and fails fast if it's too old. Use `pip-audit` or `safety check` in your CI to catch dependency drift before production.

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

Community Notes

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