A tax form parser takes the text and positions that OCR found on a page and turns them into named fields. It pairs each label with its value, keeps table rows together, cleans amounts, dates and checkboxes into typed values, and gives every value a fixed field name. The output is data a spreadsheet or program can use directly.
Pairing labels with values in a tax form parser
A tax form parser pairs labels with values by position and by the form's ruled structure. Each box on a tax form holds a printed label and a space for the value. The parser finds the label text, finds the border that encloses it, and assigns the value inside that border to the label's field.
The input to this step is a set of text fragments, each with a bounding box: a rectangle in page coordinates. The parser does not see the page the way a person does. It sees "1a Total ordinary dividends" at one position and "2,140.55" at another, and has to decide whether they belong together.
Three clues settle most pairs:
- Containment. If both fragments sit inside the same ruled box, they belong together. This is the strongest clue when the scan shows the lines clearly.
- Proximity and direction. On most tax forms the value sits below or to the right of its label. A value directly under a label is a better match than one the same distance away to the left.
- Box number. Labels usually start with a box number such as "1a" or "4". A parser can use that number to check that it found the right label, and to fall back on the form's known box order when lines are faint.
Hard cases come from crowded layouts. A label that wraps onto two lines must be joined before matching. Two boxes stacked with no gap can share a border, so containment alone cannot split them. A value printed slightly over a box line can fall in either box. When the clues disagree, a good parser lowers its confidence and sends the field for review instead of picking one.
Pairing gives each value a box. It does not yet give it a meaning that holds across forms, because box numbers repeat: Box 1 is wages on a W-2 and interest on a 1099-INT. The section on why box numbers alone break extracted tax data explains why each value also needs a field name.
How does a tax form parser read tables like 1099-B lots?
A tax form parser reads tables like 1099-B lots by finding the column headers first, then grouping text into rows by vertical position. Each row becomes one record, and each cell in the row is assigned to the column whose header sits above it. The goal is to keep every value of one sale together.
A 1099-B lists sales of stock and other property. The IRS Instructions for Form 1099-B name the per-sale boxes, including Box 1a description of property, Box 1b date acquired, Box 1c date sold or disposed, Box 1d proceeds, Box 1e cost or other basis and Box 1g wash sale loss disallowed. On a broker's statement those boxes usually become columns, with one row per lot.
Rows go wrong in a few predictable ways:
- Wrapped descriptions. A long security name wraps to a second line. The parser must attach the second line to the row above, not start a new row with only a description.
- Missing cells. A lot with no wash sale has a blank in that column. The parser has to keep the blank in place so the next value does not slide left into the wrong column.
- Page breaks. A table that runs to the next page repeats its headers there, or does not. Rows on the second page must use the same columns.
- Subtotals. Statements often print subtotals by term or by type. Those lines look like rows but are sums, and counting them as lots doubles the total.
A parser can check its own table work. The sum of the proceeds column across all lots should equal any total the statement prints, and every row should have a date sold and proceeds. A row missing those two is likely a wrapped line or a subtotal. What each 1099-B column means for a sale, and how basis and wash sales work, belongs to the 1099-B guides.
Cleaning amounts, dates and checkboxes in tax document parsing
Cleaning, in tax document parsing, turns OCR strings into typed values. An amount such as "$1,234.00" becomes the number 1234.00. A date such as "12/31/25" becomes a full calendar date. An "X" in a small square becomes true. Without this step, every downstream sum and comparison works on text and fails.
Each kind of value has its own rules.
Amounts
Strip the dollar sign, spaces and thousands separators, then read the number. Keep the cents. The IRS General Instructions for Forms W-2 and W-3 ask employers to make dollar entries on Copy A "without the dollar sign and comma but with the decimal point (00000.00)," and to show the cents. Recipient copies and substitute statements often print dollar signs and commas anyway, so the parser must handle both. Watch for:
- Parentheses or a trailing minus, which some statements use for negative amounts.
- A missing decimal point from a faint scan, which turns 1,234.00 into 123400.
- An empty box versus a printed 0.00. These mean different things and should stay different: null for empty, zero for zero.
Dates
Dates come as "12/31/2025", "2025-12-31", "Dec 31, 2025" or "12/31/25". The parser should store one format and keep the original string. Two-digit years need a rule tied to the form's tax year. Some statements print a word in a date column instead of a date. If the word is printed on the page, it is a value to keep as text, not a misread to force into a date.
Checkboxes
A checkbox is a small square that holds an X, a check mark, a filled square or nothing. The parser reads the mark inside the square's border, ignoring the label next to it. The IRS Instructions for Form 1099-DIV list Box 11, FATCA filing requirement, as a checkbox for U.S. payers reporting under chapter 4. A stray mark from a stamp can look like a check, so low-contrast marks deserve review.
Identifiers
TINs and account numbers keep their exact characters. The parser should check the pattern, such as XX-XXXXXXX for an EIN, and never "clean" an identifier by dropping characters it does not expect.
Multi-page and continuation sheets in a tax form parser
A tax form parser handles multi-page forms by treating related pages as one document before it pairs any values. A K-1 with attached statements, a 1099-B that runs to many pages of lots, or a broker statement with several forms in it all need their pages grouped and ordered first.
Continuation pages cause three problems. The first is grouping: page 4 of a statement must be tied to pages 1 to 3, not read as a new form. The second is carried context: a page of lots may not repeat the account number or the term heading, so the parser must carry those forward. The third is splitting: one combined statement can hold a 1099-DIV, a 1099-INT and a 1099-B section, and each needs its own schema.
The IRS Instructions for Form 1099-B note that brokers using substitute statements may report a customer's sales, interest, dividends and foreign taxes on a single statement. A parser that assumes one form per document will mix those sections. The fix is to classify each section by its heading and box labels, then parse each section with its own form's rules.
Page numbers help when they are printed. "Page 3 of 7" confirms order and tells the parser when the statement ends. When page numbers are missing, the parser can use repeated headers, account numbers and running subtotals to tell which pages belong together.
Splitting a mixed file into separate forms before parsing is a job of its own, and the guide to extracting data from scanned PDF forms covers what to do with image-only PDFs that hold no text layer.
Testing a tax form parser against known values?
You test a tax form parser by running it on forms whose correct values you already know, then comparing field by field. A small test set of real layouts, each with a hand-checked answer file, shows which fields the parser gets wrong and on which layouts. Totals and math checks catch more.
A worked parse of one 1099-DIV
The example below is fictional. The fund company, the recipient and every amount are made up for the example. The box labels come from the IRS Instructions for Form 1099-DIV, which also describe Box 1b qualified dividends as the part of the Box 1a amount that qualifies for the lower capital gains rates.
Step 1: the OCR lines.
Example Index Funds Inc PAYER'S TIN XX-XXXXXXX
RECIPIENT'S TIN XXX-XX-1234 Casey Sample
1a Total ordinary dividends 1b Qualified dividends
$ 2,140.55 $ 1,902.10
2a Total capital gain distr. 3 Nondividend distributions
$ 418.00
4 Federal income tax withheld 5 Section 199A dividends
$ 0.00 $ 61.20
11 FATCA filing requirement [ ]
Step 2: pair labels with values. "$ 2,140.55" sits under "1a Total ordinary dividends" in the same box, so it pairs with Box 1a. "$ 1,902.10" pairs with Box 1b. "$ 418.00" sits under Box 2a. Box 3 has no value under it, so it stays empty. Box 4 pairs with "$ 0.00", Box 5 with "$ 61.20". Box 11 is an empty checkbox.
Step 3: type each value. Amounts lose the "$" and comma: 2140.55, 1902.10, 418.00, 0.00 and 61.20. Box 3 becomes null, not zero. Box 11 becomes false.
Step 4: name each field.
| Box | Field name | Typed value |
|---|---|---|
| 1a | total_ordinary_dividends | 2140.55 |
| 1b | qualified_dividends | 1902.10 |
| 2a | total_capital_gain_distributions | 418.00 |
| 3 | nondividend_distributions | null |
| 4 | federal_income_tax_withheld | 0.00 |
| 5 | section_199a_dividends | 61.20 |
| 11 | fatca_filing_requirement | false |
Step 5: check. Box 1b, 1,902.10, is not larger than Box 1a, 2,140.55, which fits the instructions' description of 1b as part of 1a. The payer TIN matches the XX-XXXXXXX pattern. Every amount parsed as a number.
Building a test set
A useful test set has several layouts of each form, not many copies of one. Include a clean PDF, a scan and a phone photo of the same form, plus forms with empty boxes, negative amounts and continuation pages. Write the expected field values by hand, once, and compare every parser run against them. Count errors per field, so you can see that a parser handles amounts well but misses checkboxes. The walkthrough of tax form data extraction puts testing inside the full flow from upload to export.
If you are building on parsed output rather than writing a parser, the posts on the tax form API cover what a structured response should carry. Schema Tax parses each supported form into a fixed schema and offers the same JSON through an API billed per page; the plans and API access section lists what each tier includes.