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

[bug] Redact Call.inputs when the class is printed/logged #1221

Open
CalebCourier opened this issue Jan 24, 2025 · 4 comments
Open

[bug] Redact Call.inputs when the class is printed/logged #1221

CalebCourier opened this issue Jan 24, 2025 · 4 comments
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@CalebCourier
Copy link
Collaborator

Describe the bug
Sometimes users need to pass sensitive information as kwargs when running a Guard. One example is api_key. When a Guard is called, i.e. guard(), kwargs are captured as part of the Call class for Guard History. The history objects stay on the client machine, but should still be redacted when printed or logged by the client.

To Reproduce

import os
from guardrails import Guard
from rich import print

guard = Guard()


guard(
    model="gpt-3.5-turbo",
    messages=[{
        "role": "user",
        "content": "Hello, world!"
    }],
    api_key=os.environ.get("OPENAI_API_KEY")
)


print(guard.history.last.inputs)

Expected behavior
Potentially sensitive kwargs should be redacted.

Library version:
0.6.x

Additional context
We already have redaction logic in Call.to_interface for this exact reason. We should just be able to override __str__ and __repr__ and reuse the same redaction technique.
See also:
#1213
#1217

@abhishek9sharma
Copy link
Contributor

abhishek9sharma commented Feb 1, 2025

Hi @CalebCourier I was trying something like this abhishek9sharma@3a9513d.
It works for a normal print but not when I use rich. It does work for both when I use print(str(guard.history.last.inputs))
not sure what I am missing something here.

@abhishek9sharma
Copy link
Contributor

Any guidance on this ?

@abhishek9sharma
Copy link
Contributor

@CalebCourier any advice on this

@CalebCourier
Copy link
Collaborator Author

Hi @abhishek9sharma, sorry for the delayed response. I think it makes sense that __str__ is working only for print. Try also adding __repr__ for rich.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants