Skip to content

Number getting converted into scientific notation in metadata.text_as_html #3871

Open

Description

@sahil0094

Problem Description

When using partition_html() and extracting table metadata via chunk.metadata.text_as_html, numeric values are being automatically converted to exponential notation.

Example

  • Input Number: 478923
  • Converted Output: 4.7e+05

Steps to Reproduce

  1. Use partition_html() on an HTML file
  2. Chunking using chunk by title function and extracting tabular data
  3. Access chunk.metadata.text_as_html
  4. Observe numeric value conversion

Expected Behavior

  • Numeric values should be preserved in their original format
  • No automatic scientific notation conversion

Environment Details

  • Unstructured Library Version: 0.10.28
  • Python Version: 3.11.0rc1
  • Environment: databricks runtime 15.4 LTS ML

Potential Impact

This automatic conversion can cause data integrity issues, especially in financial or scientific data processing.

Suggested Investigation

  • Review number parsing/serialization logic
  • Check type conversion mechanisms in metadata handling

Activity

  1. added
    bug
    on Jan 17, 2025
  2. gyx09212214-prog commented on Jun 12, 2026

    @gyx09212214-prog

    I opened PR #4373 with regression coverage for this behavior on the partition_html(..., chunking_strategy="by_title") path.

    I wasn't able to reproduce the scientific-notation conversion on current main with a minimal HTML table fixture, but the added test locks in the expected behavior that numeric-looking table cell text such as 478923, 000001, and 0.000123 remains unchanged in chunked metadata.text_as_html.

  3. zeweihan commented on Jun 19, 2026

    @zeweihan

    Wanted to add a concrete angle on why this matters beyond general "data integrity": in legal and financial document pipelines (fee schedules, payment terms, loan amortization, M&A consideration tables) every digit is a covenant term, so the silent coercion 478923 → 4.7e+05 is not a cosmetic formatting bug — it's a contract-terms corruption bug.

    Concrete failure mode we hit: a text_as_html table cell holding 4,923,847 (purchase price in USD) survives ingestion as a float, round-trips through to_html(), and on re-parse becomes 4,920,000. A 3,847 delta is enough to be a material breach of a payment provision, and there is no signal anywhere in the element metadata that the value was lossy. That's the dangerous part — unlike an OCR error, a scientifically-notated number looks clean to every downstream validator, so it sails straight into the RAG store. Confidence scores (ref #4320) don't help here because the extraction "succeeded" with no structural ambiguity; the loss happened in numeric coercion, not layout.

    On where the conversion likely originates: when a table is materialized through a DataFrame, integer cells get upcast to float64 the moment a mixed-type column appears, and pandas to_html() with the default float_format falls back to a %g-style representation that switches to scientific notation once the exponent crosses its threshold. The token 478923 was never preserved as a string — it was round-tripped through float.

    A few things that would fully close this for regulated-domain users:

    1. Carry original_text per cell. The round-trip partition → text_as_html → partition should be the identity function on cell values. Preserving the source lexeme as a string sidesteps the dtype-inference problem entirely and is the only approach that survives re-parsing.
    2. Expose float_format passthrough. Mirroring DataFrame.to_html(float_format=...) so callers in finance/legal can force e.g. lambda x: f"{x:.0f}" or, better, opt out of numeric coercion for the table-HTML path.
    3. Disable dtype inference for detected currency / percentage / legal-amount cells. A cell matching (USD\s?)?[\d,]+(\.\d+)? should never be cast to float; treat it as opaque text the same way we'd treat a citation string.

    Point 1 is the load-bearing one for us — a regulated-domain RAG pipeline fundamentally cannot tolerate a serialization step that isn't lossless on its own native output format.

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

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions