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

Allow the user to specify only off-topic entries. #23

Merged
merged 5 commits into from
Dec 11, 2024

Conversation

JosephCatrambone
Copy link
Contributor

@JosephCatrambone JosephCatrambone commented Dec 6, 2024

Prior to this change there was no way for a user to specify only a set of topics that was off limit. There needed to be at least one item on topic. With these changes, a user can now specify only restricted topics.

The pass criteria are now: no off-topic matters AND (at least one on-topic matter IF they exist).

Example:

r = RestrictToTopic(invalid_topics=["tacos",])

r.validate("I went to the grocery store on Thursday.")
PassResult(outcome='pass', ...)

r.validate("I decide to buy some Taco Bell.")
FailResult(outcome='fail', error_message="Invalid topics found: ['tacos']", ...)
r = RestrictToTopic()
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
----> 1 r = RestrictToTopic()

File ~/Source/restricttotopic/validator/main.py:118, in RestrictToTopic.__init__(self, valid_topics, invalid_topics, device, model, llm_callable, disable_classifier, classifier_api_endpoint, disable_llm, on_fail, zero_shot_threshold, llm_threshold, **kwargs)
    115     self._invalid_topics = invalid_topics
    117 if not (self._valid_topics or self._invalid_topics):
--> 118     raise ValueError("Either valid topics or invalid topics must be specified.")
    120 self._device = (
    121     str(device).lower()
    122     if str(device).lower() in ["cpu", "mps"]
    123     else int(device)
    124 )
    125 self._model = model

ValueError: Either valid topics or invalid topics must be specified.
r = RestrictToTopic(valid_topics=["tacos",])

r.validate("I decide to buy some Taco Bell.")
PassResult(outcome='pass', value_override=<class 'guardrails.classes.validation.validation_result.PassResult.ValueOverrideSentinel'>, metadata=None, validated_chunk=None)

@zsimjee zsimjee merged commit 7290756 into tryolabs:main Dec 11, 2024
@JosephCatrambone JosephCatrambone deleted the jc/allow_only_invalid branch December 11, 2024 22:33
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

Successfully merging this pull request may close these issues.

2 participants