Prepare and fill federal and state tax return PDF forms
Prepare federal and state income tax returns: read source documents, compute taxes, fill official PDF forms.
Year-agnostic — always look up current-year brackets, deductions, and credits. Never reuse prior-year values.
Organize all work into subfolders of the working directory:
working_dir/
source/ ← user's source documents (W-2, 1099s, prior return, CSVs)
work/ ← ALL intermediate files (extracted data, field maps, computations)
tax_data.txt ← extracted figures from source docs
computations.txt ← all tax math (federal, state, capital gains)
f1040_fields.json ← field discovery dumps
f8949_fields.json
f1040sd_fields.json
ca540_fields.json
expected_*.json ← verification expected values
forms/ ← blank downloaded PDF forms
f1040_blank.pdf
f8949_blank.pdf
f1040sd_blank.pdf
ca540_blank.pdf
output/ ← final filled PDFs + fill script
fill_YEAR.py ← the fill script
f1040_filled.pdf
f8949_filled.pdf
f1040sd_filled.pdf
ca540_filled.pdf
Create these folders at the start. Keep the working directory clean — no loose files.
These rules prevent context blowouts that cause compaction:
python3 -c "
import pdfplumber
with pdfplumber.open('source/document.pdf') as pdf:
for p in pdf.pages: print(p.extract_text())
"
work/tax_data.txt on first read.work/. Do NOT use --search repeatedly.work/computations.txt so they survive compaction.Ask the user what documents they have. Read files from source/ (move them there if needed). Use pdfplumber for PDFs, Read tool for CSVs.
Save all extracted figures to work/tax_data.txt immediately — one section per document with every relevant number.
You MUST ask the user every one of these questions and WAIT for answers before proceeding. Do NOT skip this step even if you think you know the answers from memory or source documents. Tax returns are legal documents.
Do NOT proceed to Step 3 until the user has answered. "Same as last year" counts as confirmation.
Research from IRS.gov and FTB.ca.gov:
Save to work/computations.txt.
Save all line values to work/computations.txt.
Rounding rule: Form 8949 and Schedule D must use exact cents matching the 1099-B / 1099-DA source documents. Only Form 1040 rounds to the nearest whole dollar (Line 7 = round of Schedule D Line 16). Do NOT round amounts on 8949 or Schedule D.
Save to forms/ directory.
IRS: Use /irs-prior/ for prior-year forms (/irs-pdf/ is always current year):