Skip to content

fix: return an empty string when RegexTextExtractor's group does not participate - #13500

Closed
xubenqiang wants to merge 1 commit into
deepset-ai:mainfrom
xubenqiang:fix/regex-extractor-empty-capture-group
Closed

xubenqiang wants to merge 1 commit into
deepset-ai:mainfrom
xubenqiang:fix/regex-extractor-empty-capture-group

Conversation

@xubenqiang

Copy link
Copy Markdown

Fixes #13484

Related Issues

Proposed Changes

RegexTextExtractor._extract_from_text returned match.group(1) whenever the pattern had groups, even when the first group did not participate in the match:

RegexTextExtractor(regex_pattern=r"Score: (\d+)|N/A").run(text_or_messages="N/A")
# before: {"captured_text": None}
# after:  {"captured_text": ""}

The component declares str output, so None broke downstream components. The no-match path already returns ""; do the same when the group captured nothing.

How did you test it?

$ hatch run test:unit test/components/extractors/test_regex_text_extractor.py --no-cov
27 passed

Two new tests cover an alternation whose first branch does not match and an optional first group. With the source change reverted, exactly those two fail:

FAILED ...::test_first_capture_group_outside_match_returns_empty_string
FAILED ...::test_first_capture_group_not_participating_returns_empty_string
2 failed, 25 passed

Also ran ruff check and ruff format --check on both changed files: clean.

Notes for the reviewer

This re-lands the fix from #12896, which the first-PR limit closed while #12863 was pending. Credit to @gauravch-code for the original change.

No release note for docs/CI, but this is user-facing, so I added releasenotes/notes/regex-text-extractor-empty-capture-group-5f3c9a1e7d2b4a68.yaml.

…participate

`RegexTextExtractor._extract_from_text` returned `match.group(1)` even when
the first group did not participate in the match (for example `Score: (\d+)|N/A`nagainst `N/A`), so `run` produced `None` although the component declares a
`str` output. Return `"` in that case, matching the no-match value, and
cover both an alternation and an optional group.

Re-lands the fix from deepset-ai#12896, which was closed by the first-PR limit.

Fixes deepset-ai#13484
Copilot AI balanced review requested due to automatic review settings October 30, 2026 17:05
@xubenqiang
xubenqiang requested a review from a team as a code owner October 30, 2026 17:05
@xubenqiang
xubenqiang removed the request for review from a team October 30, 2026 17:05
@vercel

vercel Bot commented Oct 30, 2026

Copy link
Copy Markdown
Contributor

@xubenqiang is attempting to deploy a commit to the deepset Team on Vercel.

A member of the Team first needs to authorize it.

@CLAassistant

CLAassistant commented Oct 30, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

@HaystackBot

Copy link
Copy Markdown
Contributor

Hi @xubenqiang, thanks a lot for your contribution! 🙏

We noticed that the Contributor License Agreement (CLA) check (license/cla) hasn't passed yet, so we've temporarily moved this PR to draft and paused the review assignment.

To get your PR reviewed, please sign the CLA via the link in the license/cla check below (or in the CLA bot comment). As soon as the check turns green, this PR will automatically be marked ready for review again and a reviewer will be re-assigned.

@HaystackBot
HaystackBot removed the request for review from davidsbatista October 30, 2026 18:22
@HaystackBot HaystackBot added the cla-pending PR is in draft until the contributor signs the CLA label Oct 30, 2026
@HaystackBot
HaystackBot marked this pull request as draft October 30, 2026 18:22
@github-actions github-actions Bot added the P3 Low priority, leave it in the backlog label Nov 2, 2026

@chrikrah chrikrah left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@xubenqiang the #13484 script now prints '' where it printed None. Nothing blocks a merge here.

# git archive c50f042 (merge base 8e38c63), Python 3.12, run from the export root
$ python repro.py      # the #13484 script
{'captured_text': '7'}
{'captured_text': ''}
{'captured_text': ''}
# with regex_text_extractor.py from 8e38c63 the last two print None, and your two new tests fail here too
# not run: the rest of the suite, ruff

Could you sign the CLA? Until then the bot keeps this in draft.

@HaystackBot

Copy link
Copy Markdown
Contributor

Hi @xubenqiang, just a friendly reminder: this PR is still in draft because the Contributor License Agreement (CLA) hasn't been signed yet. We'd love to review your contribution! Please sign the CLA via the link in the license/cla check, and this PR will automatically be marked ready for review.

@davidsbatista

Copy link
Copy Markdown
Contributor

We can't review/merge approve without you signing the CLA

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-pending PR is in draft until the contributor signs the CLA P3 Low priority, leave it in the backlog topic:tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

RegexTextExtractor returns captured_text None when the capture group is not part of the match

6 participants