Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Guardrails as a tool #30

Open
bboynton97 opened this issue Nov 7, 2024 · 0 comments
Open

Add Guardrails as a tool #30

bboynton97 opened this issue Nov 7, 2024 · 0 comments

Comments

@bboynton97
Copy link
Contributor

As an MVP, give agents the ability to validate output against guardrails:

pii_guard.validate("My phone number is 555-555-6868")

Example code from a meeting:

from openai import OpenAI

from guardrails import Guard, install

# CLI Installation
# guadrails hub install hub://guadrails/detect_pii

install("hub://guardrails/detect_pii")
install("hub://guardrails/toxic_language")
from guardrails.hub import DetectPII
from guardrails.hub import ToxicLanguage

client = OpenAI()
pii_guard = Guard().use(DetectPII(pii_entities=["EMAIL_ADDRESS", "PHONE_NUMBER"]))
toxic_language_guard = Guard().use(ToxicLanguage())
combo_guard = Guard().use_many(DetectPII(pii_entities=["EMAIL_ADDRESS", "PHONE_NUMBER"]), ToxicLanguage())

client(
    model='gpt-4o-mini',
    messages=[{
        "role": "user",
        "content": "What is the meaning of life?"
    }]
)

pii_guard(
    model='gpt-4o-mini',
    messages=[{
        "role": "user",
        "content": "What is the meaning of life?"
    }]
)

toxic_language_guard(
    model='gpt-4o-mini',
    messages=[{
        "role": "user",
        "content": "What is the meaning of life?"
    }]
)

pii_guard.validate("My phone number is 555-555-6868")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant