Skip to content

import error #24

@fraz-prod

Description

@fraz-prod

I am trying to run readme code of python after installing it like this

!guardrails hub install hub://tryolabs/restricttotopic

then run the code example

# Import Guard and Validator
from guardrails.hub import RestrictToTopic
from guardrails import Guard

# Setup Guard
guard = Guard().use(
    RestrictToTopic(
        valid_topics=["sports"],
        invalid_topics=["music"],
        disable_classifier=True,
        disable_llm=False,
        on_fail="exception"
    )
)

guard.validate("""
In Super Bowl LVII in 2023, the Chiefs clashed with the Philadelphia Eagles in a fiercely contested battle, ultimately emerging victorious with a score of 38-35.
""")  # Validator passes

guard.validate("""
The Beatles were a charismatic English pop-rock band of the 1960s.
""")  # Validator fails

I am getting below error

 ImportError: cannot import name 'RestrictToTopic' from 'guardrails.hub' (/usr/local/lib/python3.10/dist-packages/guardrails/hub/__init__.py)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions