guardrails-ai/guardrails
Adding guardrails to large language models.
What it solves
Guardrails provides a way to ensure that LLM-based applications are reliable and safe. It solves the problem of unpredictable LLM outputs by detecting and mitigating risks (such as toxicity or competitor mentions) and ensuring that the model generates data in a specific, structured format.
How it works
The framework operates through two primary mechanisms:
- Input/Output Guards: It uses "validators"—pre-built or custom risk measures—to intercept and check the text entering or leaving an LLM. If a validation fails, the system can trigger specific actions, such as raising an exception.
- Structured Data Generation: It integrates with Pydantic models to force LLMs to return data in a defined schema. It achieves this via function calling for supported models or by optimizing the prompt for those that do not support it.
Additionally, Guardrails can be deployed as a standalone REST API server using Flask, allowing applications to interact with it remotely.
Who it’s for
Developers building AI applications who need to enforce safety constraints, prevent hallucinations, or ensure that LLM outputs are consistently parseable as structured data.
Highlights
- Guardrails Hub: A collection of pre-built validators for common risks.
- Pydantic Integration: Seamlessly converts LLM responses into structured Python objects.
- Flexible Deployment: Can be used as a library or as a standalone server.
- LLM Agnostic: Works with both proprietary and open-source models.
Related
- Project
- Project
- Project
- Dispatch
- Project