Repository navigation
fix: return empty string when RegexTextExtractor's first capture group does not participate - #13648
Mystery01092000 wants to merge 1 commit into
Conversation
…ot participate
When the pattern matched but its first capture group took no part in the
match (e.g. 'Score: (\d+)|N/A' on 'N/A', or an unmatched optional group),
match.group(1) returned None and the component emitted
{'captured_text': None} despite declaring a str output.
Return '' in that case, consistent with the no-match result.
Fixes deepset-ai#13484
|
@Mystery01092000 is attempting to deploy a commit to the deepset Team on Vercel. A member of the Team first needs to authorize it. |
|
Hi @anakin87 @davidsbatista, this picks up the fix for #13484 after #13500 went stale over the CLA. It returns an empty string when the first capture group doesn't take part in the match, and adds three tests. Could one of you take a look when you have a moment? Thanks! |
|
Hi @Mystery01092000, thanks a lot for your contribution! 🙏 We noticed that the Contributor License Agreement (CLA) check ( To get your PR reviewed, please sign the CLA via the link in the |
In order for us to start the reviewing process please sign the CLA |
|
close in favor of #13649 since CLA was not signed |
Related Issues
Proposed Changes:
Problem.
RegexTextExtractordeclarescaptured_text: str, but it returned{"captured_text": None}when the pattern matched and its first capture group did not take part in the match. Two examples: an alternation likeScore: (\d+)|N/Amatched against"N/A", and an optional group likeAnswer:( \w+)?matched against"Answer:". A downstream component then receivesNonewhere it expects a string.Cause.
_extract_from_textreturnedmatch.group(1)whenever the pattern had groups. Python'srereturnsNonefor a group that did not participate in the match.Fix. Return
match.group(1) or "", so the result is""in that case. I picked""over falling back to the whole match (group(0)) because:""is already what the component returns when nothing matches, so callers can use one emptiness check;The
runand_extract_from_textdocstrings now describe this case. I also added a release note underfixes.How did you test it?
The repro script from the issue, run with
hatch -e test run python repro.py:I added three unit tests to
test/components/extractors/test_regex_text_extractor.py: an unmatched alternation branch, an unmatched optional group, and the same case passed in as aChatMessagelist.Other checks:
hatch run fmt-check: all checks passed, all files already formattedhatch run test:types:Success: no issues found in 568 source filesI ran these locally on Windows with Python 3.12. I did not run the full unit suite.
Notes for the reviewer
#13500 made the same change and a reviewer confirmed it worked, but it was closed unmerged because its author never signed the CLA. Before that, #12896 was closed by the first-PR limit. This PR picks up the same approach, with an extra test for the
ChatMessagepath.This PR was fully generated with an AI assistant, which also ran the tests and checks listed above.
Checklist
fix:,feat:,build:,chore:,ci:,docs:,style:,refactor:,perf:,test:and added!in case the PR includes breaking changes.