Repository navigation
refactor: Anthropic tool_use sweep across structured-extraction services - #3611
Merged
Merged
Conversation
Mirrors the pattern from #3396 (smart-paste property parse). The analyze_property tool with input_schema constrains the model output to typed args; tool_choice forces it. The route reads tool_use.input directly — no JSON.parse, no fence stripping, no prompt-injection surface from text-output parsing. Exports analyzeProperty so the tool_use contract can be pinned by a unit test rather than indirectly through enhanceProperty (which pulls in WHOIS/DB). Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Mirrors the pattern from #3396. classify_brand tool with input_schema (enum-bounded keller_type and confidence) constrains the model output; tool_choice forces it. The route reads tool_use.input directly — no JSON.parse, no fence stripping. Auth-relevant: keller_type and confidence='high' gate brand-hierarchy membership inheritance in autoLinkByVerifiedDomain. The schema enum hardens the SDK layer; the runtime allowlist remains as the load-bearing defense. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Mirrors the pattern from #3396. assess_prospect tool with input_schema (enum-bounded action / owner / priority / company_type) constrains the model output; tool_choice forces it. The route reads tool_use.input directly — no JSON.parse, no fence stripping, no regex code-fence extraction. Removes the malformed-JSON throw path: with tool_use the SDK either returns a typed tool-use block or no block at all. The new no-tool-use throw is caught upstream by triageEmailDomain (returns action='skip', reason='assessment_error'), matching the prior failure semantics. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Mirrors the pattern from #3396. discover_sub_brands tool with input_schema (keller_type enum bounds returned brands to {sub_brand, endorsed}) constrains the model output; tool_choice forces it. The expandHouse path reads tool_use.input directly — no JSON.parse, no fence stripping. The downstream upsert already defaults keller_type to 'sub_brand' for any drift, so the schema enum + that default jointly bound what can land in the brands table. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
This was referenced Apr 30, 2026
bokelley
added a commit
that referenced
this pull request
Apr 30, 2026
… services (issue #3621) (#3637) Closes #3621. Adds four integration tests that pin the tool_use output → DB write contract for brand-classifier, brand-enrichment/expandHouse, property-enhancement, and prospect-triage — the services migrated to typed input_schema tool invocations in PR #3611. https://claude.ai/code/session_01RFAvM1RBMzagDAcy5hxZEW Co-authored-by: Claude <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Sweep adopting the Anthropic
tool_use+input_schemapattern that PR #3396 introduced for the smart-paste property parse endpoint. Each migrated caller defines a tool withinput_schema, setstool_choice: { type: 'tool', name: '...' }to force it, and readstool_use.inputdirectly — eliminating theJSON.parse/ fence-stripping / regex-extraction class of bug and closing the prompt-injection surface that came with text-output parsing.One commit per converted file so any single conversion can be reverted independently if real-model behaviour diverges.
Converted
server/src/services/property-enhancement.ts—analyze_propertytool (publisher assessment, confidence enum)server/src/services/brand-classifier.ts—classify_brandtool (auth-relevant viaautoLinkByVerifiedDomain; keller_type + confidence enums)server/src/services/prospect-triage.ts—assess_prospecttool (action / owner / priority / company_type enums)server/src/services/brand-enrichment.ts—discover_sub_brandstool (house expansion; keller_type enum)Each migration ships a unit test that pins: tool definition with the right
input_schemaenums,tool_choiceforces the tool, defensive fall-through when the model returns notool_useblock, and the runtime allowlist still bounds the result.Surveyed but not migrated
server/src/utils/llm.ts,server/src/utils/batch.ts— generic completion / batch helpers that return free-form text by design.server/src/routes/webhooks.ts—extractInsightsWithClaudereturns a 2-4 sentence insight summary; not JSON-parsed.server/src/routes/addie-admin.ts— diagnosis endpoint returns a free-form analysis string.server/src/services/prospect-cleanup.ts— already usestool_use(multi-turn agent loop with explicit tools); final response is intentional prose.server/src/addie/**— explicitly out of scope per the brief (Addie's main chat router is a complex orchestration path).Test plan
npm run typecheckfrom repo rootvitest runfor the four new unit test files (20/20 pass)🤖 Generated with Claude Code