Skip to content

fix: validate search_accounts filters (raise on unknown keys) - #14

Merged
jschfflr merged 1 commit into
mainfrom
fix/search-accounts-filter-validation
Jul 9, 2026
Merged

fix: validate search_accounts filters (raise on unknown keys)#14
jschfflr merged 1 commit into
mainfrom
fix/search-accounts-filter-validation

Conversation

@jschfflr

@jschfflr jschfflr commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

The bug (Medium-High — silent-wrong)

search_accounts(**filters) forwarded filters unvalidated. Apollo silently drops unknown keys and returns an unfiltered default page that looks like a real match:

search_accounts(query="Red and Bundle")            # → 28,149 accounts, "Google" first  ❌
search_accounts(q_organization_name="Red and Bundle")  # → the 1 real match             ✅

Real impact reported: trusted the "Google" result → wrong company attached to a deal + a duplicate account created before it was caught.

Fix

  • Added ACCOUNT_SEARCH_FILTERS allowlist (from Apollo docs: q_organization_name, account_stage_ids, account_label_ids, sort_by_field, sort_ascending).
  • search_accounts now raises ValueError on any unknown key before the request, naming the bad key and pointing to q_organization_name=.

Testing

  • +4 unit tests (rejects unknown key / never calls API / message names the key / all documented filters pass).
  • Live-verified: unknown key now raises; q_organization_name still returns the correct single match.
  • ruff ✅ · pyright ✅ · 184 tests ✅

Note: CLI accounts search --query already maps to q_organization_name, so it's unaffected. No version bump (left for release time).

🤖 Generated with Claude Code

Apollo's /accounts/search silently drops unrecognised filter keys and
returns an unfiltered default page that looks like a real match. Passing
e.g. query='Red and Bundle' returned 28k accounts ('Google' first)
instead of the intended match, causing wrong-company attribution.

search_accounts now validates **filters against an allowlist of the keys
Apollo actually supports and raises ValueError (naming the bad key and
pointing to q_organization_name) before hitting the API. Fail-loud beats
silent-wrong. Live-verified.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
peqy[bot]
peqy Bot approved these changes Jul 9, 2026

@peqy peqy Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Validating filter keys before calling Apollo prevents the silent-unfiltered default page bug, and the tests cover the regression + message guidance well. Ship it.

@jschfflr
jschfflr merged commit 0e75b45 into main Jul 9, 2026
4 checks passed
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