[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"project-71089":3},{"id":4,"name":5,"fullName":6,"owner":7,"repo":5,"description":8,"homepage":9,"htmlUrl":10,"language":11,"languages":10,"totalLinesOfCode":10,"stars":12,"forks":13,"watchers":14,"openIssues":15,"contributorsCount":16,"subscribersCount":16,"size":16,"stars1d":17,"stars7d":18,"stars30d":19,"stars90d":16,"forks30d":16,"starsTrendScore":20,"compositeScore":21,"rankGlobal":10,"rankLanguage":10,"license":22,"archived":23,"fork":23,"defaultBranch":24,"hasWiki":25,"hasPages":25,"topics":26,"createdAt":10,"pushedAt":10,"updatedAt":32,"readmeContent":33,"aiSummary":34,"trendingCount":16,"starSnapshotCount":16,"syncStatus":35,"lastSyncTime":36,"discoverSource":37},71089,"guardrails","guardrails-ai\u002Fguardrails","guardrails-ai","Adding guardrails to large language models.","https:\u002F\u002Fwww.guardrailsai.com\u002Fdocs",null,"Python",6993,620,39,22,0,23,45,147,69,114.38,"Apache License 2.0",false,"main",true,[27,28,29,30,31],"ai","foundation-model","gpt-3","llm","openai","2026-06-12 04:00:58","\u003Cdiv align=\"center\">\n\n\u003Cimg src=\"https:\u002F\u002Fraw.githubusercontent.com\u002Fguardrails-ai\u002Fguardrails\u002Fmain\u002Fdocs\u002Fassets\u002FGuardrails-ai-logo-for-dark-bg.svg#gh-dark-mode-only\" alt=\"Guardrails AI Logo\" width=\"600px\">\n\u003Cimg src=\"https:\u002F\u002Fraw.githubusercontent.com\u002Fguardrails-ai\u002Fguardrails\u002Fmain\u002Fdocs\u002Fassets\u002FGuardrails-ai-logo-for-white-bg.svg#gh-light-mode-only\" alt=\"Guardrails AI Logo\" width=\"600px\">\n\n\u003Chr>\n\n[![License](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FLicense-Apache_2.0-blue.svg)](https:\u002F\u002Fopensource.org\u002Flicenses\u002FApache-2.0)\n![PyPI - Python Version](https:\u002F\u002Fimg.shields.io\u002Fpypi\u002Fpyversions\u002Fguardrails-ai)\n[![Downloads](https:\u002F\u002Fstatic.pepy.tech\u002Fbadge\u002Fguardrails-ai\u002Fmonth)](https:\u002F\u002Fpepy.tech\u002Fproject\u002Fguardrails-ai)\n[![CI](https:\u002F\u002Fgithub.com\u002Fguardrails-ai\u002Fguardrails\u002Factions\u002Fworkflows\u002Fci.yml\u002Fbadge.svg)](https:\u002F\u002Fgithub.com\u002Fguardrails-ai\u002Fguardrails\u002Factions\u002Fworkflows\u002Fci.yml)\n[![codecov](https:\u002F\u002Fcodecov.io\u002Fgh\u002Fguardrails-ai\u002Fguardrails\u002Fgraph\u002Fbadge.svg?token=CPkjw91Ngo)](https:\u002F\u002Fcodecov.io\u002Fgh\u002Fguardrails-ai\u002Fguardrails)\n[![Checked with pyright](https:\u002F\u002Fmicrosoft.github.io\u002Fpyright\u002Fimg\u002Fpyright_badge.svg)](https:\u002F\u002Fmicrosoft.github.io\u002Fpyright\u002F)\n[![X (formerly Twitter) Follow](https:\u002F\u002Fimg.shields.io\u002Ftwitter\u002Ffollow\u002Fguardrails_ai)](https:\u002F\u002Fx.com\u002Fguardrails_ai)\n[![Discord](https:\u002F\u002Fimg.shields.io\u002Fdiscord\u002F1085077079697150023?logo=discord&label=support&link=https%3A%2F%2Fdiscord.gg%2Fgw4cR9QvYE)](https:\u002F\u002Fdiscord.gg\u002FU9RKkZSBgx)\n[![Static Badge](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FDocs-blue?link=https%3A%2F%2Fwww.guardrailsai.com%2Fdocs)](https:\u002F\u002Fguardrailsai.com\u002Fguardrails\u002Fdocs)\n[![Static Badge](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FBlog-blue?link=https%3A%2F%2Fwww.guardrailsai.com%2Fblog)](https:\u002F\u002Fwww.guardrailsai.com\u002Fblog)\n[![Gurubase](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FGurubase-Ask%20Guardrails%20Guru-006BFF)](https:\u002F\u002Fgurubase.io\u002Fg\u002Fguardrails)\n\n\u003C\u002Fdiv>\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\u002FOutput 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:\u002F\u002Fguardrailsai.com\u002Fhub\u002F).\n2. Guardrails help you generate structured data from LLMs.\n\n\n\u003Cdiv align=\"center\">\n\u003Cimg src=\"https:\u002F\u002Fraw.githubusercontent.com\u002Fguardrails-ai\u002Fguardrails\u002Fmain\u002Fdocs\u002Fassets\u002Fwith_and_without_guardrails.svg\" alt=\"Guardrails in your application\" width=\"1500px\">\n\u003C\u002Fdiv>\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:\u002F\u002Fguardrailsai.com\u002Fhub\u002F) to see the full list of validators and their documentation.\n\n\u003Cdiv align=\"center\">\n\u003Cimg src=\"https:\u002F\u002Fraw.githubusercontent.com\u002Fguardrails-ai\u002Fguardrails\u002Fmain\u002Fdocs\u002Fassets\u002Fguardrails_hub.gif\" alt=\"Guardrails Hub gif\" width=\"600px\">\n\u003C\u002Fdiv>\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:\u002F\u002Fguardrails\u002Fregex_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:\u002F\u002Fguardrails\u002Fcompetitor_check\n    guardrails hub install hub:\u002F\u002Fguardrails\u002Ftoxic_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:\u002F\u002Fdocs.pydantic.dev\u002Flatest\u002Fapi\u002Fbase_model\u002F) 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:\u002F\u002Fguardrails\u002Ftwo_words --guard-name=two-word-guard`\n4. Start the dev server: `guardrails start --config=.\u002Fconfig.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:\u002F\u002Flocalhost:8000\u002Fguards\u002Ftwo-word-guard\u002Fopenai\u002Fv1\u002F\"\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:\u002F\u002Fdiscord.gg\u002Fgw4cR9QvYE) or [Twitter](https:\u002F\u002Ftwitter.com\u002Fguardrails_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:\u002F\u002Fguardrailsai.com\u002Fguardrails\u002Fdocs\u002Fhow-to-guides\u002Fusing_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:\u002F\u002Fguardrailsai.com\u002Fguardrails\u002Fdocs\u002Fhow-to-guides\u002Fcustom_validators).\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:\u002F\u002Fdiscord.gg\u002Fgw4cR9QvYE) or [Twitter](https:\u002F\u002Ftwitter.com\u002Fguardrails_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","Guardrails 是一个用于为大型语言模型添加防护措施的 Python 框架。其核心功能包括运行输入\u002F输出防护，以检测、量化并减轻特定类型的风险，并帮助生成结构化数据。技术特点上，Guardrails 提供了预构建的风险度量（称为“验证器”），这些验证器可以组合成输入和输出防护，从而拦截语言模型的输入和输出。适用于需要提高基于 LLM 的应用程序可靠性和安全性的场景，如金融、医疗等对数据准确性和安全性要求较高的领域。",2,"2026-06-11 03:35:51","high_star"]