Skip to content

Reject keywords that normalize to empty - #84

Open
fallintoplace wants to merge 1 commit into
openai:mainfrom
fallintoplace:fix/reject-empty-normalized-keywords
Open

Reject keywords that normalize to empty#84
fallintoplace wants to merge 1 commit into
openai:mainfrom
fallintoplace:fix/reject-empty-normalized-keywords

Conversation

@fallintoplace

Copy link
Copy Markdown

Summary

  • validate keywords after the existing trailing-punctuation normalization
  • reject values that normalize to an empty string instead of compiling an empty regex alternative
  • reuse one compiled punctuation pattern for validation and matching
  • add regression coverage for empty, punctuation-only, and mixed keyword lists

Why

A configured keyword such as ... was normalized to an empty string. The resulting empty regex alternative matched every input, so benign text triggered the keyword filter. The inherited competitor configuration had the same failure mode.

Failing configuration validation makes the error explicit and prevents a match-all pattern from reaching runtime.

Testing

  • uv run ruff check
  • uv run mypy src/guardrails/checks/text/keywords.py
  • uv run pyright src/guardrails/checks/text/keywords.py
  • uv run pytest -q (439 passed)

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7772d9d74e

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/guardrails/checks/text/keywords.py Outdated
@field_validator("keywords")
@classmethod
def reject_empty_sanitized_keywords(cls, keywords: list[str]) -> list[str]:
"""Reject keywords that become empty after sanitization."""

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Add Google-style sections to the validator docstring

Expand this new validator's one-line docstring with Args:, Returns:, and Raises: sections, including the ValueError condition. The repository explicitly requires these sections for every function and requires review deviations to be flagged.

AGENTS.md reference: AGENTS.md:L87-L90

Useful? React with 👍 / 👎.

@fallintoplace
fallintoplace force-pushed the fix/reject-empty-normalized-keywords branch from 7772d9d to 9f41773 Compare July 26, 2026 00:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant