Skip to content

Comments

Add uv package manager support and project-level validator registry#1416

Open
debu-sinha wants to merge 1 commit intoguardrails-ai:v0.9.1from
debu-sinha:feature/uv-compatibility
Open

Add uv package manager support and project-level validator registry#1416
debu-sinha wants to merge 1 commit intoguardrails-ai:v0.9.1from
debu-sinha:feature/uv-compatibility

Conversation

@debu-sinha
Copy link
Contributor

Closes #1412

What changed

This PR adds uv package manager support to Guardrails Hub and introduces a project-level JSON registry as a step toward removing the barrel __init__.py mutation pattern.

Changes

Phase 1 -- uv compatibility (this PR):

  • Replace importlib.import_module('pip') with sysconfig.get_paths()['purelib'] for site-packages discovery -- eliminates the hard dependency on pip being importable
  • Auto-detect uv when available via shutil.which('uv'), with GUARDRAILS_INSTALLER env var for explicit override (uv or pip)
  • Add installer_process() that routes install commands through either uv pip install or python -m pip install
  • Update install_hub_module() to use the detected installer

Phase 2a -- project-level registry (this PR):

  • Add register_validator() that writes validator metadata to .guardrails/hub_registry.json in the project root
  • Each install now writes to both the barrel __init__.py (backward compat) and the new JSON registry
  • Add guardrails hub migrate CLI command that reads existing barrel imports from hub/__init__.py in site-packages and converts them to registry entries

Installer detection precedence

  1. GUARDRAILS_INSTALLER=uv|pip env var (explicit override)
  2. shutil.which('uv') (auto-detect)
  3. Fall back to pip

Registry format

{
  "version": 1,
  "validators": {
    "guardrails/detect_pii": {
      "import_path": "guardrails_grhub_detect_pii",
      "exports": ["DetectPII"],
      "installed_at": "2025-01-01T00:00:00+00:00",
      "package_name": "guardrails-grhub-detect-pii"
    }
  }
}

How is this tested

  • 35 tests in test_validator_package_service.py (all passing) -- updated existing tests to use installer_process mock, added new tests for detect_installer, get_site_packages_location, register_validator, get_registry_path
  • 7 tests in test_installer_process.py (new) -- pip/uv command construction, error handling, NO_COLOR env var, empty package guard
  • 6 tests in test_migrate.py (new) -- no hub init, empty init, single/multiple validator migration, multi-export lines, comment/blank line handling
  • All 85 hub-related tests passing
pytest tests/unit_tests/hub/ tests/unit_tests/cli/hub/ -v
======================= 85 passed, 12 warnings in 3.70s ========================

Migration path

This is "Release A" of a two-release migration sequence:

  1. Release A (this PR): Ship hub migrate + dual-write (registry + barrel). Users can opt in to the registry while barrel stays fully functional.
  2. Release B (future): Switch runtime imports to read from registry first. Deprecate and eventually remove barrel file mutation.

- replace pip import with sysconfig for site-packages discovery
- auto-detect uv when available, with GUARDRAILS_INSTALLER env override
- add installer_process() that routes to uv pip or pip based on detection
- add project-level JSON registry at .guardrails/hub_registry.json
- add hub migrate command to convert barrel imports to registry format
- update install flow to write registry entries alongside __init__.py

Signed-off-by: debu-sinha <debusinha2009@gmail.com>
@vercel
Copy link

vercel bot commented Feb 20, 2026

@debu-sinha is attempting to deploy a commit to the Guardrails AI Team on Vercel.

A member of the Team first needs to authorize it.

@debu-sinha
Copy link
Contributor Author

Hey @CalebCourier -- this implements the approach we discussed in #1412.

Quick summary of what's here:

  • uv auto-detection: shutil.which('uv') with GUARDRAILS_INSTALLER env var override, so hub install works out of the box with uv
  • sysconfig instead of pip import: no more importlib.import_module('pip') for finding site-packages
  • Project-level registry: .guardrails/hub_registry.json written alongside the barrel file on every install
  • hub migrate command: converts existing barrel imports to registry format for users upgrading

This is the "Release A" half -- dual-writes to both barrel and registry, nothing breaks for existing users. Happy to walk through any of it or adjust the approach.

@CalebCourier CalebCourier changed the base branch from main to v0.9.1 February 23, 2026 15:28
@CalebCourier
Copy link
Collaborator

CalebCourier commented Feb 23, 2026

Thanks @debu-sinha! I repointed this from main to a version branch so that I can run our full regression test suite on it after merging [edit] before going to main.[edit] Reviewing in full now. Will keep you updated on the release cycle for this feature.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure this is worth including for the following reason: In order for a user to run this they would have to update the guardrails-ai package. Upon update, there will not be any entries in their hub/__init__.py. In order to repopulate it, they would need to perform the hub installs again which would automatically populate the new json registry as well.

If there's a scenario I'm not seeing where this would work please let me know but otherwise I think it's worth dropping this from the feature set.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants