Skip to content

Commit

Permalink
fix workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
aaravnavani committed Sep 12, 2024
1 parent 538343b commit 3548c1d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 43 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ type:
qa:
make lint
make type
make tests
make test
60 changes: 18 additions & 42 deletions tests/test_validator.py
Original file line number Diff line number Diff line change
@@ -1,43 +1,19 @@
# to run these, run
# pytest test/test-validator.py

import pytest
from guardrails import Guard
from validator import CompetitorCheck

# We use 'refrain' as the validator's fail action,
# so we expect failures to always result in a guarded output of None
# Learn more about corrective actions here:
# https://www.guardrailsai.com/docs/concepts/output/#%EF%B8%8F-specifying-corrective-actions
competitors_list = [
"Acorns",
"Citigroup",
"Citi",
"Fidelity Investments",
"Fidelity",
"JP Morgan Chase and company",
"JP Morgan",
"JP Morgan Chase",
"JPMorgan Chase",
"Chase" "M1 Finance",
"Stash Financial Incorporated",
"Stash",
"Tastytrade Incorporated",
"Tastytrade",
"ZacksTrade",
"Zacks Trade",
]

guard = Guard().use(CompetitorCheck(competitors=competitors_list, use_local=True, on_fail="refrain"))


def test_pass():
test_output = "HomeDepot is not a competitor"
res = guard.parse(test_output)

assert(res.validated_output == test_output)

def test_fail():
test_output = "Acorns, with its extensive global network, has become a powerhouse in the banking sector, catering to the needs of millions across different countries, like Citi. I also like my RothIRA account with Fidelity Investments."
res = guard.parse(test_output)

assert(not res.validation_passed)
from guardrails.hub import CompetitorCheck

# Setup Guard with CompetitorCheck validator
guard = Guard().use(
CompetitorCheck, ["Apple", "Samsung"], "exception"
)

# Test passing response (no competitor mentioned)
def test_competitor_check_pass():
response = guard.validate("The apple doesn't fall far from the tree.")
assert response.validation_passed is True

# Test failing response (competitor mentioned)
def test_competitor_check_fail():
with pytest.raises(Exception) as e:
guard.validate("Apple just released a new iPhone.")
assert "Validation failed for field with errors:" in str(e.value)

0 comments on commit 3548c1d

Please sign in to comment.