New Features
Run Guardrails as a local server
Guardrails 0.5.0 introduces thestart command to the guardrails cli. This allows you to run the Guardrails validation engine as a local python server.
Benefits of using Guardrails this way include:
- Less strain on your main process/thread
- The Guardrails server utilizes Gunicorn to take advantage of multiple threads
- Supported on Linux and MacOS by default, supported on Windows when using WSL
- Declare your Guards in a separate config and reference them by name in your app to keep your code slim and clean
- Install
- Create a
config.py
- Start the Guardrails server
- Use the Guard in your application
Generate structured data with smaller models:
As part of Guardrails 0.5.0, we’re launching constrained decoding support for HuggingFace models. This allow you to generate structured data that matches your schema with confidence. Example:Improvements
LiteLLM is now easier to use within Guardrails
When calling models through LiteLLM, specifying thellm_api argument is now optional. Instead, just pass the model name.
Example:
New public interface for generating JSON schema-based function calling tools
Guardrails has supported function calling for OpenAI Chat models for a while and previously would auto-insert a function to specify the schema when a Guard was created via a Pydantic model. In Guardrails 0.5.0, you can use this same pattern regardless of how the Guard was initialized. We also made the process more transparent by allowing you to generate the tool first and decide when to pass it as a keyword argument. For models that support openai tool/function calling (gpt-4o, gpt-4-turbo, or gpt-3.5-turbo), you can extend your existing tools with Guard.json_function_calling_tool()
Example:
Guard.use() now works for all Guards
Previously, constructing a Guard via the use method was only supported for unstructured response schemas. It now supports specifying validators for any Guard regardless of the initialization method (Guard(), Guard.from_rail(), Guard.from_pydantic(), etc.). Guard.use() is also the new method of applying input validations to a Guard.
Example of applying input validation to the Prompt:
Guard.use() on a Guard with structured output, you can specify a JSON Path to identify which property the Validator(s) should be assigned to.
Example:
Backwards-incompatible changes
Args vs Kwargs
In previous versions, most of the Guardrails interfaces utilized positional arguments for most parameters. This could be tedious when specifying optional arguments. In 0.5.0, for our public interfaces, only required arguments are positional; all optional arguments are keyword only. If you previously called you Guard like this:Validators have moved
We’ve moved validators to the Guardrails Hub, reducing the core package size for faster installations and smoother workflows. Targeted validation: Install only the validators you need, streamlining your project and dependencies. New naming: Some validator names changed for clarity and consistency. Head to the hub to find the updated names and grab your validators!AsyncGuard’s for Async LLMs
In v0.4.4, we introduced a newAsyncGuard for use with asynchronous LLM’s. As of 0.5.0, support for async LLM’s was removed from the Guard class and is now only supported in the AsyncGuard class. This should provide better type hinting while developing as well as make the interface simpler and easier to use.
Prompt Primitives have moved
In v0.4.5, we introducedxml prompt primitives to replace the previous json constants. In 0.5.0, the json prompt primitives have a different meaning and will likely continue to evolve. If you wish to keep the same constructed prompts as before, you must utilize the new xml prompt primitives.
Removal of support for older dependency versions
As of 0.5.0, we no longer directly support to following versions of dependencies:- Python 3.8
- Pydantic 1.x
- OpenAI 0.x