Comments (10)
One possible way might be to allow users to specify an optional pydantic model in the tag.
The model would need to have fields that matches the field names, and then all validation can be done in the pydantic model instead of in the XML
<object name="bank_run" pydantic="BankRun">
<string
name="explanation"
description="A paragraph about what a bank run is."
on-fail-length="reask"
/>
<url
name="follow_up_url"
description="A web URL where I can read more about bank runs."
on-fail-valid-url="filter"
/>
</object>
and then
from pydantic import BaseModel
class BankRun(BaseModel):
explanation: str
follow_up_url: str
There's many advantages to this, we can specify default values, optional fields, all the other stuff pydantic supports, and the wider python ecosystem in general since pydantic validation is very extensible, people can use this way to use the validators
lib to plug into the pydantic schema too.
NOTE: this would also make using the @register_validator
redundant
One other effect of this is that users won't need to know arbitrary tags, eg. like <url>
or <string>
, it'll just all be <field>
or similar, all the data types will live in python.
This does loosely tie the RAIL format to Python which may not be preferable, but would be much more natural to work with in Python IMO.
from guardrails.
@cktang88 Nice, I think this would be super useful! I like this framing of the solution and the idea of adding field
as a data type.
I do think that supporting primitives like url
, code
etc. is nice so that the spec isn't too reliant on Python. I plan to add support for rail
in other languages in the future. However, to make the support for pydantic work, adding field
as a datatype along with the existing data types makes a lot of sense.
I'll get a PR started to add this.
from guardrails.
Started a PR #35 that starts to address this issue (see details there)
from guardrails.
@devenbhooshan this is a pretty neat suggestion!
I'll think some more about what the best interface for integrating existing python validator library could be. One way to do this could be that for supported types (e.g. email, IP address, etc.), validators provided in the python validator lib is supported by default. Wdyt?
from guardrails.
would be cool to integrate w/ Pydantic directly https://docs.pydantic.dev/ which seems to be one of the most common Python schema validation libs
from guardrails.
Pydantic support would be awesome. +1
from guardrails.
@cktang88 @oliverbj could definitely add Pydantic support for schema validation. The Validator
classes in Guardrails took inspiration from Pydantic's Validators.
Do you have an idea of what an integration with Pydantic's schema validation would be like within Guardrails?
from guardrails.
Could we generate a models.py
file with code describing pydantic models from a guardrails spec?
from guardrails.
@irgolic I think so! I'll have to double check what the edge cases are around nested structures, but it should be doable.
That would make it pretty easy for users so that they don't have to make double effort to first write the spec and then the pydantic models.
from guardrails.
This was added in #35 (docs on how to use Pydantic). I'll close this issue out -- thanks for the suggestion everyone!
from guardrails.
Related Issues (20)
- Add better_profanity as a validator which takes care of word dividers HOT 4
- Dead link to docs page HOT 2
- [bug] Importing guardrails raises a deprecation warning for old validators HOT 1
- [bug] JSON validation converts null values to True:bool HOT 1
- No capability to disable telemetry via env var [bug] HOT 2
- [bug] Message: guardrails-cli[6204] , ERROR Failed to inspect HOT 8
- Guardrails Langchain integration with streamable AgentExecutor HOT 7
- Automatically open `hub.guardrailsai.com/tokens` url when running guardrails configure
- [feat] Support for image inputs in prompts HOT 1
- [bug] Endpoint is reachable Validator "Zero-click" Vulnerability HOT 5
- [bug]: Guardrails hub token not getting generated HOT 7
- Import Error - Cannot import name 'SensitiveTopic' from 'guardrails.hub' HOT 4
- How to Deploy Guardrails with Hub via Docker image HOT 4
- [bug] detect-prompt-injetion validator fails to install from hub HOT 2
- [feat] Support defaults
- [feat] add a `quiet` option to `guardrails hub install`
- [feat] Update validator imports in notebooks to hub
- [bug] llm_api function triggering twice HOT 6
- [bug] OpenAI v1.x AsyncClient Does Not Work in Guardrails as Expected
- [bug] Guardrails prohibits OpenAI from utilizing env-var based API key HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from guardrails.