You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Number getting converted into scientific notation in metadata.text_as_html #3871
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
Use partition_html() on an HTML file
Chunking using chunk by title function and extracting tabular data
Access chunk.metadata.text_as_html
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
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.
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:
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.
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.
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.
Activity
gyx09212214-prog commentedon Jun 12, 2026
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
mainwith a minimal HTML table fixture, but the added test locks in the expected behavior that numeric-looking table cell text such as478923,000001, and0.000123remains unchanged in chunkedmetadata.text_as_html.zeweihan commentedon Jun 19, 2026
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+05is not a cosmetic formatting bug — it's a contract-terms corruption bug.Concrete failure mode we hit: a
text_as_htmltable cell holding4,923,847(purchase price in USD) survives ingestion as a float, round-trips throughto_html(), and on re-parse becomes4,920,000. A3,847delta 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
float64the moment a mixed-type column appears, and pandasto_html()with the defaultfloat_formatfalls back to a%g-style representation that switches to scientific notation once the exponent crosses its threshold. The token478923was never preserved as a string — it was round-tripped through float.A few things that would fully close this for regulated-domain users:
original_textper cell. The round-trippartition → text_as_html → partitionshould 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.float_formatpassthrough. MirroringDataFrame.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.(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.