{"id":13492552,"url":"https://github.com/guardrails-ai/guardrails","last_synced_at":"2026-03-16T20:05:10.308Z","repository":{"id":142427317,"uuid":"594609262","full_name":"guardrails-ai/guardrails","owner":"guardrails-ai","description":"Adding guardrails to large language models.","archived":false,"fork":false,"pushed_at":"2025-12-06T05:14:11.000Z","size":44949,"stargazers_count":6112,"open_issues_count":17,"forks_count":485,"subscribers_count":33,"default_branch":"main","last_synced_at":"2025-12-09T13:19:41.947Z","etag":null,"topics":["ai","foundation-model","gpt-3","llm","openai"],"latest_commit_sha":null,"homepage":"https://www.guardrailsai.com/docs","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/guardrails-ai.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2023-01-29T04:11:35.000Z","updated_at":"2025-12-09T10:24:28.000Z","dependencies_parsed_at":null,"dependency_job_id":"866a95aa-d012-46d3-b8af-7ca372e76fe6","html_url":"https://github.com/guardrails-ai/guardrails","commit_stats":{"total_commits":2224,"total_committers":72,"mean_commits":30.88888888888889,"dds":0.79181654676259,"last_synced_commit":"5652e0f1c67026171f1498eeb7a4504c45002b4e"},"previous_names":["shreyar/guardrails"],"tags_count":73,"template":false,"template_full_name":null,"purl":"pkg:github/guardrails-ai/guardrails","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/guardrails-ai%2Fguardrails","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/guardrails-ai%2Fguardrails/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/guardrails-ai%2Fguardrails/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/guardrails-ai%2Fguardrails/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/guardrails-ai","download_url":"https://codeload.github.com/guardrails-ai/guardrails/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/guardrails-ai%2Fguardrails/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":27645114,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-12-10T02:00:12.818Z","response_time":54,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ai","foundation-model","gpt-3","llm","openai"],"created_at":"2024-07-31T19:01:07.011Z","updated_at":"2026-03-16T20:05:10.301Z","avatar_url":"https://github.com/guardrails-ai.png","language":"Python","funding_links":[],"categories":["LLM Tools","🤖 LLM \u0026 Chatbot Testing","🛠️ Librerías para Usar NLP en Español","🛡️ エージェントセキュリティ","Python","🧺 Curated catalog","\u003ca name=\"Python\"\u003e\u003c/a\u003ePython","5. Governance \u0026 Risk","A01_文本生成_文本对话","Tools","🏗️ Reference Implementations \u0026 Case Studies","[↑](#table-of-contents)Tools \u003ca name=\"tools\"\u003e\u003c/a\u003e","LLM and Agent Observability","Defenses","NLP","Learning","LLM and AI System Testing","开源工具","Privacy and Safety","🛡 AI Safety and Guardrails","Observability / evals","Organisations/Companies","Alignment \u0026 Training","🚧 Guardrails \u0026 Compliance","LLM Guardrails / Security","Safety \u0026 Governance","10. AI Safety, Alignment \u0026 Interpretability","Security \u0026 Privacy Agents","8. Agent Security \u0026 Guardrails","Security \u0026 Safety","Agent Security and Robustness","🧠 Structured Generation \u0026 Control","Security and Privacy Considerations","🧰 Tools","Tool Families","Tools of Trade","LLM安全","Security and robustness","Runtime Monitoring and Guardrails","⚙️ Agent Operations"],"sub_categories":["🛡️ Guardrails (librerias y modelos)","その他の標準","Guardrails \u0026 Safety","大语言对话模型及数据","Robustness","T15 · Guardrails \u0026 Security","Jailbreak \u0026 Policy Enforcement (Guardrails)","Training Time Attack","Repositories","安全护栏","Benchmarks","Open Source","Guardrails \u0026 Output Safety","Sandboxing \u0026 Execution","Post-Exploitation Agents","Guardrail Frameworks","Resources","Benchmark Reality Check (real-world tool use)","Output Structure \u0026 Validation","Comparison Guides","Typed-output and structuring tools","Guardrails \u0026 Firewalls","Libraries","🔒 Security \u0026 Governance"],"readme":"\u003cdiv align=\"center\"\u003e\n\n\u003cimg src=\"https://raw.githubusercontent.com/guardrails-ai/guardrails/main/docs/assets/Guardrails-ai-logo-for-dark-bg.svg#gh-dark-mode-only\" alt=\"Guardrails AI Logo\" width=\"600px\"\u003e\n\u003cimg src=\"https://raw.githubusercontent.com/guardrails-ai/guardrails/main/docs/assets/Guardrails-ai-logo-for-white-bg.svg#gh-light-mode-only\" alt=\"Guardrails AI Logo\" width=\"600px\"\u003e\n\n\u003chr\u003e\n\n[![License](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)\n![PyPI - Python Version](https://img.shields.io/pypi/pyversions/guardrails-ai)\n[![Downloads](https://static.pepy.tech/badge/guardrails-ai/month)](https://pepy.tech/project/guardrails-ai)\n[![CI](https://github.com/guardrails-ai/guardrails/actions/workflows/ci.yml/badge.svg)](https://github.com/guardrails-ai/guardrails/actions/workflows/ci.yml)\n[![codecov](https://codecov.io/gh/guardrails-ai/guardrails/graph/badge.svg?token=CPkjw91Ngo)](https://codecov.io/gh/guardrails-ai/guardrails)\n[![Checked with pyright](https://microsoft.github.io/pyright/img/pyright_badge.svg)](https://microsoft.github.io/pyright/)\n[![X (formerly Twitter) Follow](https://img.shields.io/twitter/follow/guardrails_ai)](https://x.com/guardrails_ai)\n[![Discord](https://img.shields.io/discord/1085077079697150023?logo=discord\u0026label=support\u0026link=https%3A%2F%2Fdiscord.gg%2Fgw4cR9QvYE)](https://discord.gg/U9RKkZSBgx)\n[![Static Badge](https://img.shields.io/badge/Docs-blue?link=https%3A%2F%2Fwww.guardrailsai.com%2Fdocs)](https://guardrailsai.com/guardrails/docs)\n[![Static Badge](https://img.shields.io/badge/Blog-blue?link=https%3A%2F%2Fwww.guardrailsai.com%2Fblog)](https://www.guardrailsai.com/blog)\n[![Gurubase](https://img.shields.io/badge/Gurubase-Ask%20Guardrails%20Guru-006BFF)](https://gurubase.io/g/guardrails)\n\n\u003c/div\u003e\n\n## News and Updates\n- **[Feb 12, 2025]** We just launched Guardrails Index -- the first of its kind benchmark comparing the performance and latency of 24 guardrails across 6 most common categories! Check out the index at index.guardrailsai.com\n\n## What is Guardrails?\n\nGuardrails is a Python framework that helps build reliable AI applications by performing two key functions:\n1. Guardrails runs Input/Output Guards in your application that detect, quantify and mitigate the presence of specific types of risks. To look at the full suite of risks, check out [Guardrails Hub](https://guardrailsai.com/hub/).\n2. Guardrails help you generate structured data from LLMs.\n\n\n\u003cdiv align=\"center\"\u003e\n\u003cimg src=\"https://raw.githubusercontent.com/guardrails-ai/guardrails/main/docs/assets/with_and_without_guardrails.svg\" alt=\"Guardrails in your application\" width=\"1500px\"\u003e\n\u003c/div\u003e\n\n\n### Guardrails Hub\n\nGuardrails Hub is a collection of pre-built measures of specific types of risks (called 'validators'). Multiple validators can be combined together into Input and Output Guards that intercept the inputs and outputs of LLMs. Visit [Guardrails Hub](https://guardrailsai.com/hub/) to see the full list of validators and their documentation.\n\n\u003cdiv align=\"center\"\u003e\n\u003cimg src=\"https://raw.githubusercontent.com/guardrails-ai/guardrails/main/docs/assets/guardrails_hub.gif\" alt=\"Guardrails Hub gif\" width=\"600px\"\u003e\n\u003c/div\u003e\n\n\n## Installation\n\n```python\npip install guardrails-ai\n```\n\n\n## Getting Started\n\n\n### Create Input and Output Guards for LLM Validation\n\n1. Download and configure the Guardrails Hub CLI.\n\n    ```bash\n    pip install guardrails-ai\n    guardrails configure\n    ```\n2. Install a guardrail from Guardrails Hub.\n\n    ```bash\n    guardrails hub install hub://guardrails/regex_match\n    ```\n3. Create a Guard from the installed guardrail.\n\n    ```python\n    from guardrails import Guard, OnFailAction\n    from guardrails.hub import RegexMatch\n\n    guard = Guard().use(\n        RegexMatch, regex=\"\\(?\\d{3}\\)?-? *\\d{3}-? *-?\\d{4}\", on_fail=OnFailAction.EXCEPTION\n    )\n\n    guard.validate(\"123-456-7890\")  # Guardrail passes\n\n    try:\n        guard.validate(\"1234-789-0000\")  # Guardrail fails\n    except Exception as e:\n        print(e)\n    ```\n    Output:\n    ```console\n    Validation failed for field with errors: Result must match \\(?\\d{3}\\)?-? *\\d{3}-? *-?\\d{4}\n    ```\n4. Run multiple guardrails within a Guard.\n    First, install the necessary guardrails from Guardrails Hub.\n\n    ```bash\n    guardrails hub install hub://guardrails/competitor_check\n    guardrails hub install hub://guardrails/toxic_language\n    ```\n\n    Then, create a Guard from the installed guardrails.\n\n    ```python\n    from guardrails import Guard, OnFailAction\n    from guardrails.hub import CompetitorCheck, ToxicLanguage\n\n    guard = Guard().use(\n        CompetitorCheck([\"Apple\", \"Microsoft\", \"Google\"], on_fail=OnFailAction.EXCEPTION),\n        ToxicLanguage(threshold=0.5, validation_method=\"sentence\", on_fail=OnFailAction.EXCEPTION)\n    )\n\n    guard.validate(\n        \"\"\"An apple a day keeps a doctor away.\n        This is good advice for keeping your health.\"\"\"\n    )  # Both the guardrails pass\n\n    try:\n        guard.validate(\n            \"\"\"Shut the hell up! Apple just released a new iPhone.\"\"\"\n        )  # Both the guardrails fail\n    except Exception as e:\n        print(e)\n    ```\n    Output:\n    ```console\n    Validation failed for field with errors: Found the following competitors: [['Apple']]. Please avoid naming those competitors next time, The following sentences in your response were found to be toxic:\n\n    - Shut the hell up!\n    ```\n\n### Use Guardrails to generate structured data from LLMs\n\n\nLet's go through an example where we ask an LLM to generate fake pet names. To do this, we'll create a Pydantic [BaseModel](https://docs.pydantic.dev/latest/api/base_model/) that represents the structure of the output we want.\n\n```py\nfrom pydantic import BaseModel, Field\n\nclass Pet(BaseModel):\n    pet_type: str = Field(description=\"Species of pet\")\n    name: str = Field(description=\"a unique pet name\")\n```\n\nNow, create a Guard from the `Pet` class. The Guard can be used to call the LLM in a manner so that the output is formatted to the `Pet` class. Under the hood, this is done by either of two methods:\n1. Function calling: For LLMs that support function calling, we generate structured data using the function call syntax.\n2. Prompt optimization: For LLMs that don't support function calling, we add the schema of the expected output to the prompt so that the LLM can generate structured data.\n\n```py\nfrom guardrails import Guard\nimport openai\n\nprompt = \"\"\"\n    What kind of pet should I get and what should I name it?\n\n    ${gr.complete_json_suffix_v2}\n\"\"\"\nguard = Guard.for_pydantic(output_class=Pet, prompt=prompt)\n\nraw_output, validated_output, *rest = guard(\n    llm_api=openai.completions.create,\n    engine=\"gpt-3.5-turbo-instruct\"\n)\n\nprint(validated_output)\n```\n\nThis prints:\n```\n{\n    \"pet_type\": \"dog\",\n    \"name\": \"Buddy\n}\n```\n\n### Guardrails Server\n\nGuardrails can be set up as a standalone service served by Flask with `guardrails start`, allowing you to interact with it via a REST API. This approach simplifies development and deployment of Guardrails-powered applications.\n\n1. Install: `pip install \"guardrails-ai\"`\n2. Configure: `guardrails configure`\n3. Create a config: `guardrails create --validators=hub://guardrails/two_words --guard-name=two-word-guard`\n4. Start the dev server: `guardrails start --config=./config.py`\n5. Interact with the dev server via the snippets below\n```\n# with the guardrails client\nimport guardrails as gr\n\ngr.settings.use_server = True\nguard = gr.Guard(name='two-word-guard')\nguard.validate('this is more than two words')\n\n# or with the openai sdk\nimport openai\nopenai.base_url = \"http://localhost:8000/guards/two-word-guard/openai/v1/\"\nos.environ[\"OPENAI_API_KEY\"] = \"youropenaikey\"\n\nmessages = [\n        {\n            \"role\": \"user\",\n            \"content\": \"tell me about an apple with 3 words exactly\",\n        },\n    ]\n\ncompletion = openai.chat.completions.create(\n    model=\"gpt-4o-mini\",\n    messages=messages,\n)\n```\n\nFor production deployments, we recommend using Docker with Gunicorn as the WSGI server for improved performance and scalability.\n\n## FAQ\n\n#### I'm running into issues with Guardrails. Where can I get help?\n\nYou can reach out to us on [Discord](https://discord.gg/gw4cR9QvYE) or [Twitter](https://twitter.com/guardrails_ai).\n\n#### Can I use Guardrails with any LLM?\n\nYes, Guardrails can be used with proprietary and open-source LLMs. Check out this guide on [how to use Guardrails with any LLM](https://guardrailsai.com/guardrails/docs/how-to-guides/using_llms).\n\n#### Can I create my own validators?\n\nYes, you can create your own validators and contribute them to Guardrails Hub. Check out this guide on [how to create your own validators](https://guardrailsai.com/guardrails/docs/hub/how_to_guides/custom_validator).\n\n#### Does Guardrails support other languages?\n\nGuardrails can be used with Python and JavaScript. Check out the docs on how to use Guardrails from JavaScript. We are working on adding support for other languages. If you would like to contribute to Guardrails, please reach out to us on [Discord](https://discord.gg/gw4cR9QvYE) or [Twitter](https://twitter.com/guardrails_ai).\n\n\n## Contributing\n\nWe welcome contributions to Guardrails!\n\nGet started by checking out Github issues and check out the [Contributing Guide](CONTRIBUTING.md). Feel free to open an issue, or reach out if you would like to add to the project!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fguardrails-ai%2Fguardrails","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fguardrails-ai%2Fguardrails","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fguardrails-ai%2Fguardrails/lists"}