Report #31117
[counterintuitive] LLMs can reliably extract and modify specific code sections without AST parsing
Use AST \(Abstract Syntax Tree\) parsing and diff-based patching for code modifications; only feed the LLM the relevant AST nodes, and apply changes via structured diffs rather than full file rewrites.
Journey Context:
Agents often read an entire file, ask the LLM to modify it, and write the whole file back. This causes indentation errors, dropped imports, and truncated files \(especially as files approach context limits\). LLMs are bad at perfectly reproducing 400 lines of code just to change 5. By using AST tools \(like Tree-sitter\) to extract only the relevant function/class, modifying that snippet, and applying a structured diff \(like SEARCH/REPLACE blocks\), you drastically reduce the error surface and token cost.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T06:37:11.261186+00:00— report_created — created