Skip to content

feat(checks)!: [OSS-13] add RegexMatching check implementation#2247

Merged
mattbit merged 13 commits intomainfrom
feature/ENG-1389-add-regex-support-to-stringmatching-check
Feb 26, 2026
Merged

feat(checks)!: [OSS-13] add RegexMatching check implementation#2247
mattbit merged 13 commits intomainfrom
feature/ENG-1389-add-regex-support-to-stringmatching-check

Conversation

@davidberenstein1957
Copy link
Copy Markdown
Member

@davidberenstein1957 davidberenstein1957 commented Feb 16, 2026

Description

  • Introduced RegexMatching class for validating text against regex patterns.
  • Enhanced string_matching.py to support regex checks alongside existing string matching.
  • Updated init.py files to include RegexMatching in the public API.
  • Added comprehensive tests for various regex scenarios, including pattern matching, case sensitivity, and normalization.
  • Refactored StringMatching to utilize a base class for shared functionality.

Related Issue

OSS-13 (available on Linear)

Type of Change

  • 📚 Examples / docs / tutorials / dependencies update
  • 🔧 Bug fix (non-breaking change which fixes an issue)
  • 🥂 Improvement (non-breaking change which improves an existing feature)
  • 🚀 New feature (non-breaking change which adds functionality)
  • 💥 Breaking change (fix or feature that would cause existing functionality to change)
  • 🔐 Security fix

@linear
Copy link
Copy Markdown

linear bot commented Feb 16, 2026

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @davidberenstein1957, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the text validation capabilities by introducing a robust RegexMatching check, allowing users to apply regular expressions for more flexible and powerful text analysis. It also refactors existing text-based checks, such as StringMatching, by introducing a common base class, which streamlines the development of future text validation features and improves the overall architecture.

Highlights

  • New RegexMatching Check: A new RegexMatching class has been introduced, allowing validation of text against regular expression patterns with configurable flags like case-insensitivity, multiline matching, and dotall.
  • Refactored Text-Based Checks: A new abstract base class, TextBasedCheck, was created to centralize common logic for extracting and validating text and target values from traces, improving code reusability and maintainability for StringMatching and future text-related checks.
  • Enhanced StringMatching Validation: The StringMatching check now includes stricter validation to ensure exactly one of keyword or keyword_key is provided, preventing ambiguous configurations.
  • Comprehensive Testing: Extensive unit tests have been added for the new RegexMatching check, covering various scenarios including basic patterns, flags, trace extraction, and error handling for invalid regex.
  • API Exposure: The new RegexMatching check has been exposed in the public API of the giskard.checks module and its builtin submodule.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • libs/giskard-checks/src/giskard/checks/init.py
    • Imported RegexMatching class.
    • Added RegexMatching to the __all__ export list.
  • libs/giskard-checks/src/giskard/checks/builtin/init.py
    • Imported RegexMatching from string_matching module.
    • Added RegexMatching to the __all__ export list.
  • libs/giskard-checks/src/giskard/checks/builtin/string_matching.py
    • Updated module docstring to reflect multiple string matching implementations.
    • Introduced TextBasedCheck abstract base class for common text and target extraction logic.
    • Refactored StringMatching to inherit from TextBasedCheck.
    • Removed text and text_key fields from StringMatching as they are now handled by TextBasedCheck.
    • Modified StringMatching's run method to utilize the _extract_and_validate method from the base class.
    • Updated StringMatching's validate_keyword_or_keyword_key to enforce that exactly one of keyword or keyword_key is provided.
    • Added new RegexMatching class for validating text against regex patterns, inheriting from TextBasedCheck.
    • Implemented RegexMatching with fields for pattern, pattern_key, and boolean flags for ignore_case, multiline, dotall, and ascii_only.
    • Added validation for RegexMatching to ensure exactly one of pattern or pattern_key is provided.
    • Implemented the run method for RegexMatching to perform regex search with specified flags and handle invalid patterns.
  • libs/giskard-checks/tests/builtin/test_regex_matching.py
    • Added new test file for RegexMatching check.
    • Included tests for basic regex patterns, anchors, word boundaries, character classes, and quantifiers.
    • Added tests for case-sensitive and case-insensitive matching.
    • Included tests for invalid regex patterns and unclosed groups.
    • Added tests for regex with whitespace and Unicode characters.
    • Included tests for extracting text and patterns from trace objects.
    • Added tests for multiline, dotall, and ascii_only flags.
    • Included tests for regex groups, alternation, and inline flags.
    • Added tests for edge cases like unescaped special characters and empty patterns.
    • Included tests for validation of missing or conflicting pattern/pattern_key arguments.
    • Added tests for real-world patterns like email, phone numbers, and URLs.
    • Included tests for error handling when text or pattern is missing in the trace.
  • libs/giskard-checks/tests/builtin/test_string_matching.py
    • Imported pytest for enhanced testing capabilities.
    • Updated the error message assertion for missing text in trace to reflect changes in the base class error message.
    • Added a new test case test_cannot_provide_both_keyword_and_keyword_key to validate the updated StringMatching behavior.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a new RegexMatching check and refactors the existing StringMatching check to use a shared TextBasedCheck base class, which is a great improvement for code reuse and maintainability. The new feature is well-tested. My review includes a few suggestions to improve code clarity, fix discrepancies between documentation and implementation, and ensure consistency in testing patterns.

@davidberenstein1957 davidberenstein1957 changed the title feat(check): add RegexMatching check implementation feat(check): ENG-1389 add RegexMatching check implementation Feb 16, 2026
@davidberenstein1957 davidberenstein1957 changed the title feat(check): ENG-1389 add RegexMatching check implementation feat(checks): ENG-1389 add RegexMatching check implementation Feb 16, 2026
Base automatically changed from feature/giskard-v3 to main February 17, 2026 15:32
@Hartorn Hartorn requested a review from a team as a code owner February 17, 2026 15:32
davidberenstein1957 and others added 4 commits February 18, 2026 08:55
closes: #ENG-1389

- Introduced RegexMatching class for validating text against regex patterns.
- Enhanced string_matching.py to support regex checks alongside existing string matching.
- Updated __init__.py files to include RegexMatching in the public API.
- Added comprehensive tests for various regex scenarios, including pattern matching, case sensitivity, and normalization.
- Refactored StringMatching to utilize a base class for shared functionality.
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
…ation

- Changed Makefile commands to use 'uv run' for linting and formatting tasks.
- Updated docstring in RegexMatching class to clarify that the pattern is matched against raw text without normalization.
- Added assertions in tests to ensure error messages are not None for various regex validation scenarios.
- Updated the regex pattern in RegexMatching to correctly escape the dollar sign, ensuring proper matching of price formats.
@davidberenstein1957 davidberenstein1957 force-pushed the feature/ENG-1389-add-regex-support-to-stringmatching-check branch from 3d37518 to 5850095 Compare February 18, 2026 07:56
henchaves and others added 3 commits February 19, 2026 11:16
- Removed ignore_case, multiline, dotall, ascii_only parameters from RegexMatching
- Updated docstring examples to use inline modifiers (?i), (?m), (?s), (?a)
- Updated tests to use inline modifiers instead of flag parameters
- Fixed SyntaxWarning by using raw string for docstring
davidberenstein1957 and others added 2 commits February 25, 2026 10:45
…mports

- Removed the string_matching.py file and its contents.
- Updated imports in the __init__.py file to reflect the new text_matching module.
@henchaves henchaves changed the title feat(checks): ENG-1389 add RegexMatching check implementation feat(checks): [OSS-13] add RegexMatching check implementation Feb 26, 2026
@henchaves henchaves changed the title feat(checks): [OSS-13] add RegexMatching check implementation feat(checks)!: [OSS-13] add RegexMatching check implementation Feb 26, 2026
@mattbit mattbit merged commit 99ae334 into main Feb 26, 2026
17 checks passed
@mattbit mattbit deleted the feature/ENG-1389-add-regex-support-to-stringmatching-check branch February 26, 2026 12:15
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.

3 participants