diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index fcd78e6c3..d475a54a4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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; diff --git a/guardrails/validator_service.py b/guardrails/validator_service.py index 293755d8e..7a58612b8 100644 --- a/guardrails/validator_service.py +++ b/guardrails/validator_service.py @@ -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.""" @@ -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( @@ -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( diff --git a/tests/integration_tests/test_guard.py b/tests/integration_tests/test_guard.py index 0d736cc80..182d64e32 100644 --- a/tests/integration_tests/test_guard.py +++ b/tests/integration_tests/test_guard.py @@ -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, @@ -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: