Repository navigation
fix: return an empty string when RegexTextExtractor's capture group is not in the match - #12896
Closed
gauravch-code wants to merge 1 commit into
Closed
gauravch-code wants to merge 1 commit into
gauravch-code wants to merge 1 commit into
Conversation
…s not in the match
gauravch-code
requested review from
bogdankostic
and removed request for
a team
September 23, 2026 20:09
Contributor
|
@gauravch-code is attempting to deploy a commit to the deepset Team on Vercel. A member of the Team first needs to authorize it. |
Contributor
|
Hi @gauravch-code, thanks for your interest in contributing to Haystack! 🙏 ⛔ First-time contributors can have at most 1 open pull request in this repository until it has been approved, so this PR was closed automatically. Your open pull request #12863 is unaffected. Once it has been approved by a maintainer, you are welcome to open more PRs. Feel free to reopen this one at that point. See the contributing guidelines for details. This is an automated message to help us keep the review queue healthy. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related Issues
RegexTextExtractor. Reproduction below.Proposed Changes:
RegexTextExtractorreturnsmatch.group(1)whenever the pattern has a capture group. When the pattern matches but that group is not part of the match,group(1)isNone. This happens with the other branch of an alternation, or with an optional group. The component then returns{"captured_text": None}even though its output type isstr. For "nothing captured" it should return{"captured_text": ""}, which is what #10152 / #10304 settled on for the no-match case.A common place this shows up is an extract-then-route pipeline. The router fails on
Noneinstead of taking the fallback route:The fix returns
match.group(1) or "", so a group that is not part of the match gives an empty string, the same as no match at all. Matches where the group does take part are unchanged. The docstrings ofrunand_extract_from_textnow mention this case.How did you test it?
test_first_capture_group_not_in_match_returns_empty_string, parametrized over an alternation (Answer: (\w+)|No answer found) and an optional leading group ((https://\S+)?\s*DONE). It checks both string input andChatMessageinput. Both cases fail onmainwith{'captured_text': None}and pass with the fix.hatch run test:unit test/components/extractors/test_regex_text_extractor.py: 27 passed.mainand on this branch.ruff check,ruff format --check, andhatch run test:typeson the changed files are clean; pre-commit hooks pass.Notes for the reviewer
I chose
""over returning the whole match, so that "the pattern matched but captured nothing" behaves the same as "no match". The existingtest_optional_capture_group*tests cover an optional second group and still pass.Checklist
fix:,feat:,build:,chore:,ci:,docs:,style:,refactor:,perf:,test:and added!in case the PR includes breaking changes.