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

[feat] add async guard support to langchain integration #1046

Open
dtam opened this issue Sep 3, 2024 · 7 comments
Open

[feat] add async guard support to langchain integration #1046

dtam opened this issue Sep 3, 2024 · 7 comments
Labels
enhancement New feature or request

Comments

@dtam
Copy link
Contributor

dtam commented Sep 3, 2024

Description
currently can not use AsyncGuard with the langchain integration

Why is this needed
[If you have a concrete use case, add details here.]

from langchain_openai import ChatOpenAI
from langchain_core.output_parsers import StrOutputParser
from langchain_core.prompts import ChatPromptTemplate

model = ChatOpenAI(model="gpt-4o")
from guardrails import AsyncGuard
from guardrails.hub import DetectPII
import asyncio

guard = AsyncGuard().use_many(
    DetectPII(pii_entities=["PERSON","LOCATION"])
)
prompt = ChatPromptTemplate.from_template("Answer this question {question}")
output_parser = StrOutputParser()

chain = prompt | model | guard.to_runnable() | output_parser

async def main():
    result = await chain.ainvoke({"question": "What are the top five airlines for domestic travel in the US?"})
    print(result)

asyncio.run(main())

Implementation details
That makes sense, looks like we need overloads for Async in here: https://github.com/guardrails-ai/guardrails/blob/main/guardrails/integrations/langchain/guard_runnable.py
Or probably a different AsyncGuardRunnable class

End result
should execute correctly

@dtam dtam added the enhancement New feature or request label Sep 3, 2024
@CalebCourier
Copy link
Collaborator

How does this fail currently?

@dtam
Copy link
Contributor Author

dtam commented Sep 3, 2024

sys:1: RuntimeWarning: coroutine 'AsyncGuard.validate' was never awaited

@CalebCourier
Copy link
Collaborator

That makes sense, looks like we need overloads for Async in here: https://github.com/guardrails-ai/guardrails/blob/main/guardrails/integrations/langchain/guard_runnable.py
Or probably a different AsyncGuardRunnable class

@paul-tharun
Copy link

is this on the roadmap?

Copy link

github-actions bot commented Nov 1, 2024

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 14 days.

@github-actions github-actions bot added the Stale label Nov 1, 2024
@zsimjee
Copy link
Collaborator

zsimjee commented Nov 1, 2024

unstale! back on the roadmap

@zsimjee zsimjee removed the Stale label Nov 1, 2024
Copy link

github-actions bot commented Dec 2, 2024

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 14 days.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants