Skip to content

refactor: Anthropic tool_use sweep across structured-extraction services - #3611

Merged
bokelley merged 5 commits into
mainfrom
bokelley/claude-tool-use-sweep-v2
Apr 30, 2026
Merged

bokelley merged 5 commits into
mainfrom
bokelley/claude-tool-use-sweep-v2

Conversation

@bokelley

Copy link
Copy Markdown
Contributor

Summary

Sweep adopting the Anthropic tool_use + input_schema pattern that PR #3396 introduced for the smart-paste property parse endpoint. Each migrated caller defines a tool with input_schema, sets tool_choice: { type: 'tool', name: '...' } to force it, and reads tool_use.input directly — eliminating the JSON.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_property tool (publisher assessment, confidence enum)
  • server/src/services/brand-classifier.ts — classify_brand tool (auth-relevant via autoLinkByVerifiedDomain; keller_type + confidence enums)
  • server/src/services/prospect-triage.ts — assess_prospect tool (action / owner / priority / company_type enums)
  • server/src/services/brand-enrichment.ts — discover_sub_brands tool (house expansion; keller_type enum)

Each migration ships a unit test that pins: tool definition with the right input_schema enums, tool_choice forces the tool, defensive fall-through when the model returns no tool_use block, 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 — extractInsightsWithClaude returns 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 uses tool_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

🤖 Generated with Claude Code

bokelley and others added 5 commits April 29, 2026 22:08
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]>
@bokelley
bokelley merged commit 61e806a into main Apr 30, 2026
13 checks passed
@bokelley
bokelley deleted the bokelley/claude-tool-use-sweep-v2 branch April 30, 2026 02:23
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant