Skip to content

[bug] AsyncGuard().to_runnable() method fails cause GuardRunnable is not designed to be async #1283

Open
@XyAgent

Description

@XyAgent

Describe the bug
A clear and concise description of what the bug is

To Reproduce
Steps to reproduce the behavior:

Guard call:

    from guardrails import AsyncGuard
    from guardrails.hub import EndpointIsReachable
    from guardrails.types.on_fail import OnFailAction

    guard = AsyncGuard().use_many(
        EndpointIsReachable(on_fail=OnFailAction.NOOP),
    ).to_runnable()    
    
    result = await guard.ainvoke("invalid url")
    print(result)

Code fails with AttributeError here: validated_output = response.validated_output

cause previous line (response: ValidationOutcome[OT] = self.guard.validate(input))
returns when using AsyncGuard

class GuardRunnable(BaseRunnable):
    guard: Guard

    def __init__(self, guard: Guard):
        self.name = guard.name
        self.guard = guard

    def _validate(self, input: str) -> OT:
        response: ValidationOutcome[OT] = self.guard.validate(input)
        validated_output = response.validated_output
        if validated_output is None or response.validation_passed is False:
            raise ValidationError(
                (
                    "The response from the LLM failed validation!"
                    "See `guard.history` for more details."
                )
            )
        return validated_output

Expected behavior
I guess a separate AsyncGuardRunnable should be implemented in this case to properly handle coroutines coming from validate method

Library version:
Version: 0.6.6

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions