{"id":9799,"library":"guardrails-api-client","title":"Guardrails API Client","description":"The `guardrails-api-client` is a Python library providing a simple interface to interact with the Guardrails API for AI application development. It is currently at version 0.4.0 and follows a rapid release cadence common for pre-1.0 libraries, indicating active development with potential for API changes.","status":"active","version":"0.4.0","language":"en","source_language":"en","source_url":"https://github.com/guardrails-ai/guardrails-api-client","tags":["AI","LLM","API Client","guardrails","security","moderation"],"install":[{"cmd":"pip install guardrails-api-client","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"HTTP client for making API requests.","package":"httpx"},{"reason":"Used for data validation and parsing API responses.","package":"pydantic"}],"imports":[{"symbol":"Client","correct":"from guardrails_api_client import Client"},{"note":"Useful for catching specific API error types.","symbol":"errors","correct":"from guardrails_api_client import errors"}],"quickstart":{"code":"import guardrails_api_client\nimport os\n\n# Ensure GUARDRAILS_API_KEY is set in your environment\n# Example: export GUARDRAILS_API_KEY=\"your_api_key_here\"\napi_key = os.environ.get(\"GUARDRAILS_API_KEY\", \"\")\n\nif not api_key:\n    print(\"Error: GUARDRAILS_API_KEY environment variable is not set.\")\n    print(\"Please set it before running the quickstart.\")\nelse:\n    client = guardrails_api_client.Client(\n        base_url=\"https://api.guardrails.ai\", # Or your custom base URL\n        api_key=api_key,\n    )\n\n    try:\n        # Replace 'your-guard-id' with an actual guard ID from your Guardrails account\n        response = client.v1.create_run(\n            llm_output=\"Hello, I am an AI model.\",\n            guard_id=\"your-guard-id\",\n            # ... other parameters like metadata, stream etc.\n        ).result\n\n        print(f\"Is valid: {response.is_valid}\")\n        if not response.is_valid:\n            print(f\"Reasons: {response.reasons}\")\n            print(f\"Fixed output: {response.fixed_output}\")\n\n    except guardrails_api_client.errors.V1CreateRunError as e:\n        print(f\"API Error: {e.response.json() if e.response else e}\")\n    except Exception as e:\n        print(f\"An unexpected error occurred: {e}\")\n","lang":"python","description":"Initializes the Guardrails API client, authenticates using an environment variable, and demonstrates a basic call to the `create_run` endpoint. This example checks an LLM output against a specified guard."},"warnings":[{"fix":"Always consult the official documentation and release notes when upgrading between minor versions. Pin your dependency to `guardrails-api-client~=0.4` to avoid unexpected upgrades.","message":"As a 0.x.x library, the API surface (e.g., client methods, parameters, response types, error handling) is subject to breaking changes in minor versions (e.g., 0.3.x to 0.4.x).","severity":"breaking","affected_versions":"<1.0.0"},{"fix":"Ensure the `GUARDRAILS_API_KEY` environment variable is correctly set and contains a valid API key. Verify the key's validity in your Guardrails account settings.","message":"Authentication failures (e.g., HTTP 401 Unauthorized) commonly occur if the `GUARDRAILS_API_KEY` is missing, invalid, or expired.","severity":"gotcha","affected_versions":"All"},{"fix":"Refer to the latest official documentation or the `guardrails-api-client` GitHub repository for the correct and most up-to-date API endpoint usage for your installed version.","message":"Specific API endpoint methods and their parameters (e.g., `client.v1.create_run`) can change or be renamed across versions, especially in pre-1.0 releases.","severity":"gotcha","affected_versions":"<1.0.0"}],"env_vars":null,"last_verified":"2026-04-17T00:00:00.000Z","next_check":"2026-07-16T00:00:00.000Z","problems":[{"fix":"Run `pip install guardrails-api-client`.","cause":"The `guardrails-api-client` library is not installed in your current Python environment.","error":"ModuleNotFoundError: No module named 'guardrails_api_client'"},{"fix":"Verify that your `GUARDRAILS_API_KEY` environment variable is set correctly and contains a valid API key. If running locally, restart your terminal/IDE after setting the variable.","cause":"The provided `api_key` is either missing or invalid, leading to an authentication failure with the Guardrails API.","error":"guardrails_api_client.errors.V1CreateRunError: (401 Client Error: Unauthorized for url: https://api.guardrails.ai/v1/run)"},{"fix":"Check the official Guardrails API Client documentation or GitHub repository for the correct method names and API structure for your installed version (0.4.0).","cause":"The method name `create_run` or its access path (`v1`) has changed, or you are calling an endpoint that does not exist in your client's version.","error":"AttributeError: 'V1Endpoints' object has no attribute 'create_run'"}]}