Skip to content

Commit

Permalink
Merge pull request #531 from guardrails-ai/property-path-fix
Browse files Browse the repository at this point in the history
fix empty check on setup key
  • Loading branch information
zsimjee authored Jan 10, 2024
2 parents b0eb650 + 21cf28f commit 8833c05
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 10 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -156,20 +156,20 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: 3.11.x
- name: Poetry cache
uses: actions/cache@v3
with:
path: ~/.cache/pypoetry
key: poetry-cache-${{ runner.os }}-${{ steps.setup_python.outputs.python-version }}-${{ env.POETRY_VERSION }}
- name: Install Poetry
uses: snok/install-poetry@v1
with:
virtualenvs-create: true
virtualenvs-in-project: true
installer-parallel: true
- name: Load cached venv
uses: actions/cache@v3
with:
path: .venv
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }}
- name: Install dependencies
run: |
make full;
Expand Down
16 changes: 14 additions & 2 deletions guardrails/validator_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
)


def key_not_empty(key: str) -> bool:
return key is not None and len(str(key)) > 0


class ValidatorServiceBase:
"""Base class for validator services."""

Expand Down Expand Up @@ -153,7 +157,11 @@ def validate(
iteration: Iteration,
path: str = "$",
) -> Tuple[Any, dict]:
property_path = f"{path}.{validator_setup.key}"
property_path = (
f"{path}.{validator_setup.key}"
if key_not_empty(validator_setup.key)
else path
)
# Validate children first
if validator_setup.children:
self.validate_dependents(
Expand Down Expand Up @@ -296,7 +304,11 @@ async def async_validate(
iteration: Iteration,
path: str = "$",
) -> Tuple[Any, dict]:
property_path = f"{path}.{validator_setup.key}" if validator_setup.key else path
property_path = (
f"{path}.{validator_setup.key}"
if key_not_empty(validator_setup.key)
else path
)
# Validate children first
if validator_setup.children:
await self.validate_dependents(
Expand Down
6 changes: 4 additions & 2 deletions tests/integration_tests/test_guard.py
Original file line number Diff line number Diff line change
Expand Up @@ -713,7 +713,7 @@ def test_sequential_validator_log_is_not_duplicated(mocker):
entity_extraction.PYDANTIC_RAIL_WITH_NOOP, entity_extraction.PYDANTIC_PROMPT
)

_, final_output, *rest = guard(
guard(
llm_api=get_static_openai_create_func(),
prompt_params={"document": content[:6000]},
num_reasks=1,
Expand All @@ -727,7 +727,9 @@ def test_sequential_validator_log_is_not_duplicated(mocker):
for x in guard.history.first.iterations.first.validator_logs
if x.validator_name == "OneLine"
)
assert len(one_line_logs) == len(final_output.get("fees"))
assert len(one_line_logs) == len(
guard.history.first.validation_output.get("fees")
)

finally:
if proc_count_bak is None:
Expand Down

0 comments on commit 8833c05

Please sign in to comment.