Skip to content

fix(partition): classify text as an email address only when all of it is one - #4577

Merged
cragwolfe merged 2 commits into
Unstructured-IO:mainfrom
chrikrah:fix/email-address-fullmatch
Oct 22, 2026
Merged

cragwolfe merged 2 commits into
Unstructured-IO:mainfrom
chrikrah:fix/email-address-fullmatch

Conversation

@chrikrah

@chrikrah chrikrah commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

The docstring of is_email_address() says it checks whether the text "is the email address" (unstructured/partition/text_type.py:319). But line 320 calls EMAIL_ADDRESS_PATTERN_RE.match, so only the start of the text must be an address. partition_text, partition_html, partition_docx and partition_pptx all send text through this check.

# base 9a376447, probe builds each document from the same sentence:
# "[email protected] is the address for every invoice question you have."
$ python probe_email.py
text ['EmailAddress']
html ['EmailAddress']
docx ['EmailAddress']
pptx ['EmailAddress']

On this branch the same probe prints ['NarrativeText'] for all four. The change is fullmatch on the stripped text, with two new test_is_email_address cases and one partition_text test. #957 added EmailAddress to stop a bare address from becoming a Title. A bare address still gives EmailAddress. Both EmailAddress elements in test_unstructured_ingest/expected-structured-output still pass is_email_address(), so the fixtures stay the same.

Verification

# base 9a376447, python 3.12, uv sync --frozen --group test --group lint --extra docx --extra pptx
$ pytest test_unstructured/partition/test_text_type.py test_unstructured/partition/test_text.py test_unstructured/partition/html test_unstructured/partition/test_docx.py test_unstructured/partition/test_pptx.py -q -n 4
3 failed, 895 passed   # base
3 failed, 898 passed   # this branch
# the 3 are the *_last_modified_from_filesystem tests, failing identically on both runs in an exported tree
$ pytest test_unstructured/partition/test_text_type.py test_unstructured/partition/test_text.py -q   # text_type.py reverted, tests kept
3 failed, 186 passed   # both new test_is_email_address cases and the partition_text test
$ ruff check . && ruff format --check .   # ruff 0.15.10
All checks passed!
353 files already formatted
$ make check-version
version sync would make no changes to unstructured/__version__.py.

No issue exists for this, and no open pull request touches is_email_address(). The CHANGELOG entry goes under 0.27.34-dev2. The existing test keeps "[email protected]" at False, so a mixed-case address is still a Title. This diff does not change that.

With fullmatch, any text after the address disqualifies it. Examples are a trailing period ([email protected].), a second address ([email protected], [email protected]) and a signature line such as [email protected] | +1 555 0100. Before, the prefix match made all three an EmailAddress. The strict check keeps the element from carrying text that is not the address. @cragwolfe, should trailing punctuation still count as an EmailAddress?

View guided diff

… is one

is_email_address() used re.match, so the email pattern only had to match
at the start of the text. A sentence that begins with an address, such as
"[email protected] is the address for every invoice question you
have.", became an EmailAddress element in partition_text, partition_html,
partition_docx and partition_pptx. Match the whole stripped text instead.

Signed-off-by: Christopher Krah <[email protected]>

@cragwolfe cragwolfe 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.

Reviewed exact head 692d3daaddb4e05d9cd4f8307e9949a8824ff537 with GPT Pro. No actionable defects found in the full-string email check, shared partitioner callers, or regression tests. The stricter handling of trailing punctuation and additional text matches the stated whole-value contract; surrounding whitespace remains accepted.

This approval covers the source review. Required exact-head checks (changelog, test_dockerfile, lint (3.12), test_unit (3.12), and test_ingest_src (3.12)) have no reported results; only Socket success/neutral checks are present. GitHub also reports merge conflicts. No tests were run locally.

(authored by codex)

@cragwolfe
cragwolfe merged commit 5618dca into Unstructured-IO:main Oct 22, 2026
52 checks passed
@CyMule CyMule mentioned this pull request Oct 22, 2026
linhongyu510 pushed a commit to linhongyu510/unstructured that referenced this pull request Oct 22, 2026
Drops the `-dev6` suffix so 0.27.34 can be tagged and published. There
are no code changes.

Since 0.27.33, this release contains:

- Free decode buffers sooner when restoring original elements (Unstructured-IO#4524)
- Free image buffers sooner during figure extraction (Unstructured-IO#4523)
- Honor `encoding=` in `partition_json` and `partition_ndjson` (Unstructured-IO#4483)
- Read a PowerPoint line break as a newline (Unstructured-IO#4571)
- Drop the empty entry of an email address group (Unstructured-IO#4576)
- Read CSV and TSV cells as the file holds them (Unstructured-IO#4574)
- Classify text as an email address only when all of it is one (Unstructured-IO#4577)

After merge, create the `0.27.34` GitHub release from the merge commit.
That publishes to PyPI.

<!-- This is an auto-generated description by cubic. -->
<a
href="https://cubic.dev/pr/Unstructured-IO/unstructured/pull/4582?utm_source=github"
target="_blank" rel="noopener noreferrer"
data-no-image-dialog="true"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source
media="(prefers-color-scheme: light)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img
alt="View guided diff"
src="https://www.cubic.dev/buttons/review-in-cubic-light.svg"></picture></a>
<!-- End of auto-generated description by cubic. -->
ayam04 pushed a commit to ayam04/unstructured that referenced this pull request Oct 30, 2026
Unstructured-IO#4630)

## Summary

`is_us_city_state_zip()` matches the start of the text instead of the
whole text, so any sentence whose prefix is a city/state/zip is typed
`Address`.

`partition_text()`, `partition_html()` and `partition_docx()` all call
this check before `is_possible_narrative_text()`, so a full sentence
turns into an `Address` element:

```python
partition_text(text="Doylestown, PA 18901 is where the team met last spring.")
# [Address(text='Doylestown, PA 18901 is where the team met last spring.')]
```

The docstring of the function describes a whole city/state/zip value,
and every example it lists is a bare address. Its sibling
`is_email_address()` was switched to `fullmatch` in Unstructured-IO#4577 for the same
reason ("classify text as an email address only when all of it is one");
this one kept the start-only match.

## Change

- `unstructured/partition/text_type.py`:
`US_CITY_STATE_ZIP_RE.match(...)` ->
`US_CITY_STATE_ZIP_RE.fullmatch(...)`.
- `test_unstructured/partition/test_text_type.py`: two parametrized
cases that start with an address but continue as a sentence.
- `test_unstructured/partition/test_text.py`: one `partition_text()`
regression test asserting the sentence is not typed `Address`.

The pattern in `unstructured/nlp/patterns.py` is not anchored, so every
bare-address case keeps working: the eleven existing parametrized cases
in `test_text_type.py` return identical results under both calls, and
`partition_text(filename="example-docs/fake-text.txt")` still yields
`Address | Doylestown, PA 18901`.

## Test

```text
python -m pytest test_unstructured/partition/test_text_type.py \
  --noconftest -o addopts= -p no:cacheprovider -p stub_tokenize -p stub_oxmsg -q
before: 9 failed, 105 passed   after: 9 failed, 107 passed
(the two new cases flip to pass; the nine failures are offline-env only - spaCy
`en_core_web_sm` is not installed here, so `contains_verb` returns False, and they
fail identically before and after)

python -m pytest test_unstructured/partition/test_text.py ...
before: 35 failed, 56 passed   after: 35 failed, 57 passed
(the new test flips; the rest are FileNotFound / language-model env issues)

python -m pytest test_unstructured/partition/test_text.py \
  -k does_not_make_an_address ...
1 failed before the change, 1 passed after
```

Fixes Unstructured-IO#4629


<!-- This is an auto-generated description by cubic. -->
<a
href="https://cubic.dev/pr/Unstructured-IO/unstructured/pull/4630?utm_source=github"
target="_blank" rel="noopener noreferrer"
data-no-image-dialog="true"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source
media="(prefers-color-scheme: light)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img
alt="View guided diff"
src="https://www.cubic.dev/buttons/review-in-cubic-light.svg"></picture></a>
<!-- End of auto-generated description by cubic. -->

Signed-off-by: Eapp1e <[email protected]>
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.

2 participants