Skip to content

is_us_city_state_zip() classifies a whole sentence as an Address #4629

Closed

Description

@Eapp1e

Describe the bug

is_us_city_state_zip() matches the start of the text instead of the whole text, so a sentence that merely begins with a city/state/zip is typed Address.

unstructured/partition/text_type.py:315:

return US_CITY_STATE_ZIP_RE.match(text.strip()) is not None

The docstring above it says the function "Checks if the given text is in the format of US city/state/zip code" and every example it lists is a bare address. Its sibling is_email_address() was changed to fullmatch in #4577 for exactly this reason ("classify text as an email address only when all of it is one"), and is_us_city_state_zip() was left with the start-only match.

To reproduce

from unstructured.partition.text_type import is_us_city_state_zip

is_us_city_state_zip("Doylestown, PA 18901")                              # True (correct)
is_us_city_state_zip("Doylestown, PA 18901 is where we met last spring.") # True (wrong)

partition_text() runs this check before is_possible_narrative_text(), so a whole sentence becomes an Address element:

from unstructured.partition.text import partition_text

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.')]

Same entry point in partition_html (unstructured/partition/html/parser.py:1102) and partition_docx (unstructured/partition/docx.py:1178).

Expected behavior

A bare address stays an Address; a sentence that starts with one is classified by the remaining checks (Title / NarrativeText), the same way is_email_address() already behaves.

Additional context

The pattern in unstructured/nlp/patterns.py is not anchored, so fullmatch keeps every existing bare-address case working; the eleven parametrized cases in test_unstructured/partition/test_text_type.py give identical results under both calls.

Activity

  1. added a commit that references this issue on Oct 30, 2026
    0b380d4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions