Dev.to
7/21/2026

From text-JSON parsing to Claude tool use in JobSearch
Short summary
A developer replaced 250 lines of fragile JSON-parsing and self-repair code with Anthropic's tool use API, forcing Claude to return structured data validated against a Pydantic schema. By defining a single tool with the desired output schema and using tool_choice to force it, the API returns a pre-parsed dict — eliminating markdown fences, quote issues, and retry calls entirely. The refactor deleted all five parser functions and the AI self-repair fallback in one commit.
- •Replaced 250 lines of JSON-parsing hacks with Anthropic tool use and tool_choice forcing
- •Pydantic model schema feeds directly into the API's input_schema — no extra work needed
- •All parser functions, self-repair fallback, and garbage-JSON tests deleted in one commit
Generated with AI, which can make mistakes.
Is this a good recommendation for you?



