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

Exception handling #512

Merged
merged 21 commits into from
Dec 15, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add 'other' to invalid topics in every case
zsimjee authored and CalebCourier committed Dec 14, 2023
commit 2609cef892443435334289cf02e9afd7b20f0846
6 changes: 4 additions & 2 deletions guardrails/validators/on_topic.py
Original file line number Diff line number Diff line change
@@ -214,7 +214,9 @@ def get_topic_zero_shot(
score = result["scores"][0] # type: ignore
return topic, score # type: ignore

def validate(self, value: str, metadata: Dict[str, Any]) -> ValidationResult:
def validate(
self, value: str, metadata: Optional[Dict[str, Any]]
) -> ValidationResult:
valid_topics = set(self._valid_topics)
invalid_topics = set(self._invalid_topics)

@@ -230,7 +232,7 @@ def validate(self, value: str, metadata: Dict[str, Any]) -> ValidationResult:

# Add 'other' to the invalid topics list
if "other" not in invalid_topics:
self._invalid_topics.append("other")
invalid_topics.add("other")

# Combine valid and invalid topics
candidate_topics = valid_topics.union(invalid_topics)
1 change: 0 additions & 1 deletion tests/integration_tests/validators/test_on_topic.py
Original file line number Diff line number Diff line change
@@ -26,7 +26,6 @@ def test_validate_invalid_topic_cpu_disable_llm(self):
valid_topics=["sports", "politics"],
disable_classifier=False,
disable_llm=True,
model_threshold=0.6,
)
text = "This is an article about music."
expected_result = FailResult(error_message="Most relevant topic is other.")