From text-JSON parsing to Claude tool use in JobSearch
My job-search tool had five functions whose only purpose was fixing JSON that Claude had just written. _clean_json_text , _fix_unescaped_newlines , _fix_single_quotes , _strip_markdown_wrapper , _extract_and_parse_json . There was also a sixth, _retry_json_fix , which took the broken JSON and sent it back to the model with a polite request to fix its own mess. I wrote every one of them, one bug at a time, over weeks. I was a little proud of them. That was the problem. How you end up with five parsers JobSearch is my personal tool, in production, single user: me. It ingests job offers from nine boards, and when I press "Analyze", Claude reads the offer against my CV and returns a structured verdict: score, recommendation, career track, the English level the ad actually requires. That verdict has to be JSON, because everything downstream is a database row, not prose. The first version did what every tutorial does. Ask the model for JSON in the prompt, take response.content[0].text , run json.loads on it. It worked in the demo and then production started teaching me things. The model wrapped the JSON in markdown fences, so I wrote a function to strip them. Sometimes it used single quotes, so I wrote a function to fix those. Then a description with a line break inside a string, so I wrote _fix_unescaped_newlines . Then a NaN where a number should be. Every fix was five lines, obviously correct, and came with its own tests. I still have the test names in the git history and they read like a confession: test_removes_trailing_commas , test_replaces_nan_with_null , test_replaces_infinity , test_unclosed_fence_still_strips_opening . By April the parsing layer was around 250 lines with seven strategies, chained, each catching what the previous one let through. The last resort was the AI self-repair call: if nothing parsed, send the broken output back and ask the model to repair it. A second API call, with real latency and real cost, to fix a formatting problem the first call