Skip to content

fix(checks): reject empty text matchers 馃馃馃馃 - #2786

Closed
mikemikimike wants to merge 8 commits into
Giskard-AI:mainfrom
mikemikimike:fix/reject-empty-text-matchers
Closed

fix(checks): reject empty text matchers 馃馃馃馃#2786
mikemikimike wants to merge 8 commits into
Giskard-AI:mainfrom
mikemikimike:fix/reject-empty-text-matchers

Conversation

@mikemikimike

Copy link
Copy Markdown

Description

Reject empty keyword and pattern values before text matching. This prevents Python substring matching and regex search from treating empty matchers as universal matches. The shared validation path covers both direct values and values resolved from a trace.

Related Issue

Fixes #2785

Type of Change

  • 馃敡 Bug fix (non-breaking change which fixes an issue)

Coding agents

I have read AUTONOMOUS.md and followed its PR requirements.

Checklist

  • I've read the CODE_OF_CONDUCT.md document.
  • I've read the CONTRIBUTING.md guide.
  • I've written tests for the changed behavior.
  • I've written the docstring in NumPy format for modified methods and classes where applicable.
  • No lockfile update is needed because pyproject.toml was not modified.

Validation

  • uv run --frozen --directory libs/giskard-checks pytest tests/builtin/test_string_matching.py tests/builtin/test_regex_matching.py -m "not functional" -q (63 passed)
  • uv run --frozen ruff format --check .
  • uv run --frozen ruff check .
  • uv tool run basedpyright --level error libs/giskard-checks/src libs/giskard-checks/tests
  • git diff --check

The full giskard-checks unit suite ran 935 passed / 16 skipped / 3 failed. The failures are existing RegoPolicy tests that require celine-regorus; that optional dependency intentionally has no Windows wheel, so it cannot be installed on this host.

@kevinmessiaen

Copy link
Copy Markdown
Member

Hey @mikemikimike

Thanks for the PR, it only partially fixes #2785

The case with empty string is fine, it now raises. However the following case still pass where it should fail:

StringMatching(text="The capital of France is Paris.", keyword=" ")

@mikemikimike

Copy link
Copy Markdown
Author

Addressed in the current head 6a00dd92: validation now rejects whitespace-only matchers via matcher.strip(), not just empty strings. Added regression coverage for StringMatching(keyword=" ") (and the equivalent regex case); both return an error with the expected message.

@mikemikimike
mikemikimike deleted the fix/reject-empty-text-matchers branch August 31, 2026 12:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

StringMatching and RegexMatching pass unconditionally when the keyword or pattern is empty

2 participants