Skip to content

feat(records): OpenSanctions as a records source, offline screening; fix crossref dropping every API hit - #153

Merged
JordanCoin merged 3 commits into
mainfrom
claude/open-prs-merge-review-e6z0ep
Nov 19, 2026
Merged

JordanCoin merged 3 commits into
mainfrom
claude/open-prs-merge-review-e6z0ep

Conversation

@JordanCoin

Copy link
Copy Markdown
Owner

OpenSanctions (sanctions lists, politically exposed persons) is now a records source. Before this it was reachable only inside crossref. openfoia search, records search/fetch, and the agent and MCP search tools can all use it now, and it can screen names fully offline. Part of #55 and #66.

Fixed: crossref dropped every OpenSanctions API result

Crossref called GET /search/default and then discarded results with score < 0.5. But results from /search have no score field (checked against the OpenAPI spec), so every API hit was dropped. A journalist screening names against sanctions lists through the API got "clean" every time.

It now uses POST /match/default, which returns a real 0–1 match score. This also helps privacy: the name goes in the request body, which OpenSanctions says it never logs, rather than a GET URL, which it keeps in logs for 90 days.

What's new

  • Adapter: openfoia/records/opensanctions.py, registered as opensanctions, with one code path shared by records and crossref.
    • Results name the lists, topics (sanction, PEP, crime and so on), countries and the match score.
    • openfoia search --json rows from OpenSanctions carry that score as confidence. No other source has a real score, so no other row has the field.
    • records fetch <id> -s opensanctions stores the entity in the active case.
  • Offline screening: openfoia records opensanctions-data --download asks first, then downloads about 480 MB from data.opensanctions.org.
    • The size and SHA-1 are checked against the published index, and the old file is kept until the new one verifies.
    • Once the file is on disk, openfoia search lists OpenSanctions as "searched on this machine only, nothing sent" and asks for no confirmation. Crossref uses the file automatically.
  • Hook in search.py: offline and match_confidence are optional hooks, read with getattr, so no other adapter changes. A local source never counts as contacted, never needs consent or a Tor route, and its rows carry egress: "local".
  • Keys: the key is read from env only (OPENFOIA_OPENSANCTIONS_API_KEY) and withheld over Tor. With no usable key, nothing is sent at all; before this, one request that was bound to fail still went out.
  • Requests: responses are capped at 10 MB. Redirects are not followed, except one 308 for a merged id, and only to the same host. The key is redacted from errors, and 429s are handled.

Access terms (checked 2026-11-19)

  • Every hosted API call needs a key.
  • Free keys are granted to journalists (staff or freelance), public-interest nonprofits and academics. Everyone else pays per /match query.
  • The bulk data is CC BY-NC 4.0 and needs no account.

Checks

  • Tests: 47 new tests in tests/test_records_opensanctions.py. They include local search with HTTP clients set to fail, the warning listing in local mode, confidence appearing only on OpenSanctions rows, the key withheld over Tor, and download checks (aborting sends nothing, checksum mismatch, off-host index). The crossref and egress tests were updated to match.
  • Mutation checks: the subagent that built this deliberately broke the key protections 16 ways, and the tests caught every one.
  • My review: I read the search.py change myself. A source counts as local only when its adapter says offline is True, which happens only while it is answering from the file on disk.
  • Gate: ruff clean, 1386 passed, 8 skipped.

Open questions

  • With both the file and a key present, search uses the file, which may be up to a few hours stale. Crossref uses both.
  • Offline matching is whole-name or alias only. Large crossref batches would need a name index.

Generated by Claude Code

The adapter matches names offline against the bulk targets.simple.csv when
it is present, otherwise via POST /match/default with the personal API key
(environment only, withheld over Tor). Crossref's API and local checkers
now call the adapter instead of their own HTTP and CSV code. Without a
usable key no request is sent at all.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016LaGpHLuSRHzGARb38X7YS
…cit bulk download

openfoia search: an adapter that says offline=True is searched locally and
never listed as contacted; rows get confidence only from an adapter's
match_confidence(). records search/fetch -s opensanctions work offline from
the bulk file, and 'records opensanctions-data --download' fetches it after a
warning, verifying size and SHA-1 against the published index.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016LaGpHLuSRHzGARb38X7YS
@JordanCoin
JordanCoin merged commit 1e958c5 into main Nov 19, 2026
9 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.

2 participants