pxwebapi-skills / scb-pxwebapi-v2-skill
CLAUDE.md18 starsChanged 6 days agoMITView on GitHub
This is not an application codebase. It is a Claude Code Skill package that teaches Claude how to query Statistics Sweden (SCB) via the public PxWebApi v2 at https://statistikdatabasen.scb.se/api/v2. There is no application runtime — changes here are documentation/prompt edits that get loaded when the scb-pxwebapi-v2 skill triggers. There is a build step and a test: scripts/build_zip.sh packages the distributable, and scripts/check_examples.py treats every example URL, POST body and table ID written in the markdown as an assertion to verify…
In this repository11 other files it gives its agents.
- pxwebapi-v1-generic-skill/CLAUDE.mdCLAUDE.md
- pxwebapi-v2-generic-skill/CLAUDE.mdCLAUDE.md
- ssb-chart-skill/CLAUDE.mdCLAUDE.md
- ssb-histstat-skill/CLAUDE.mdCLAUDE.md
- ssb-pxwebapi-v2-skill/CLAUDE.mdCLAUDE.md
- generic-pxweb-v1-skillSkill
- generic-pxweb-v2-skillSkill
- scb-pxwebapi-v2Skill
- ssb-chartSkill
- ssb-histstatSkill
- ssb-pxwebapi-v2Skill
The file
We split this CLAUDE.md into the rules it gives an agent
4 rules. About 0 are common, 0 are distinctive, and 4 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈0
Distinctive · estimate
This author's own choices. Worth a look.
4
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 69
Use valueCodes (camelCase) consistently in GET examples — matches the OpenAPI spec and the POST body shape, even though the API is …
- Very specific: line 82
If you added a file to references/, update the file tree in README.md too (hand-maintained.
- Very specific: line 83
If a factual claim changed, do the sibling check below and record its outcome in DEVLOG.md, including when the answer is "does not apply".
- Very specific: line 84
If you changed a step, an endpoint, a limit or the checker, redraw the matching SVG in docs/.
≈ “Common” is an estimate: at least 1 in 5 of the 29,248 CLAUDE.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
CLAUDE.md
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
What this repo is
This is not an application codebase. It is a Claude Code Skill package that teaches Claude how to query Statistics Sweden (SCB) via the public PxWebApi v2 at https://statistikdatabasen.scb.se/api/v2. There is no application runtime — changes here are documentation/prompt edits that get loaded when the scb-pxwebapi-v2 skill triggers.
There is a build step and a test: scripts/build_zip.sh packages the distributable, and scripts/check_examples.py treats every example URL, POST body and table ID written in the markdown as an assertion to verify against the live SCB API. Prose is the fixture set; drift upstream at SCB fails the build.
Commands
Requires Python 3.12+ (stdlib only) and zip/unzip.
# Verify every example URL, GET/POST query and table ID in SKILL.md + references/
python3 scripts/check_examples.py # add --quiet to hide OK lines
# Rebuild the distribution zip (required before committing content changes)
scripts/build_zip.sh # writes ./scb-pxwebapi-v2-skill.zip
scripts/build_zip.sh /tmp/fresh.zip # write elsewhere, e.g. to diff against the committed zip.github/workflows/check-scb-examples.yaml (repo root — GitHub Actions only reads workflows there) runs two jobs, check (the Python script) and zip-sync (rebuilds the zip and diff -rs it against the committed one), on push/PR touching SKILL.md, README.md, CHANGELOG.md, references/**, scripts/** or the zip, and by hand via workflow_dispatch (Actions tab → Run workflow). There is no scheduled run: the Monday cron was removed on 2026-10-13 (maintainer's call), so SCB-side drift with no local change surfaces only on the next push or manual run. Run the checker locally before a release.
At most half the rate limit, for tests too (maintainer's rule). Every request, retries included, takes a slot in scripts/ratewindow.py's sliding window: 15 per 10 s (SCB's /config says 30), a slot held 11 s. The file is identical to the SSB copy; keep it so. It replaced --delay in 0.13.0. The run ends with «N kall, høyst K per 10 s (budsjett 15)».
check_examples.py is a port of the SSB skill's checker; only the base URL, the table-ID pattern (TAB638-style), the language, the rate window and the lastPeriod staleness check differ. It asserts HTTP 200 — not that a search example finds the table the example then uses. That has to be checked by hand: ?query=folkmängd returns 200 with TAB638 on page 3 (position 47 of 117, default pageSize 20). It also skips any GET line whose path contains a space, so write multi-word searches with + if you want them checked at all; the English example (title:population AND title:month) cannot be, and was verified by hand. Write å, ä and ö percent-encoded in examples (?query=folkm%C3%A4ngden+per+m%C3%A5nad): the checker encodes URLs itself and so passes a raw ä, but an agent that copies the line into curl -g gets 200 with 0 hits and no error (found by the 0.11.2 eval, 2026-10-14). % is in the checker's safe set, so an encoded line is not encoded twice.
The /savedqueries safety rule
check_examples.py deliberately never issues POST /savedqueries — that would create persistent state on SCB's servers. Such examples are JSON-syntax-validated only. Keep this exemption if you extend the checker, and never "verify" a saved-query example by actually posting it.
Layout
SKILL.md— the skill entrypoint. Frontmatter (name,description,license,metadata.version) controls when the skill auto-triggers; the body is the operational guide Claude follows. Keep triggers (Swedish + English keywords for Swedish official statistics) in thedescription. Structure: data-integrity rule → endpoint table → tool selection → language → 6-step workflow (Steg 1–6) → pitfalls → licence → worked examples → fallback.The frontmatter
name(scb-pxwebapi-v2) is not the folder name (scb-pxwebapi-v2-skill). Claude Code triggers on the folder in practice; the frontmatter name is what counts when the package is uploaded to claude.ai, sobuild_zip.shuses it as the top-level folder inside the zip.Since 0.11.0 the file is deliberately deduplicated: each rule has one primary occurrence in
SKILL.mdplus pointers, and detail lives inreferences/. Before adding a paragraph, grep for the term — if it already appears, extend the existing occurrence or the reference file instead of writing a second one. Terms worth grepping:elimination,noteMandatory,top(),Statistikdatabasen,role.geo, rate limit.references/— deeper reference material loaded on demand. Every file exceptmcp-tools.mdandsearch-syntax.mdopens with an Innehåll list that mirrors its H2 headings; update it when you add or rename a section. There is no TOC checker script (maintainer, 2026-10-28): the numbered lines between**Innehåll**and---must equal the number of##headings:json-stat2.md— same layout as SSB's since 0.11.2: table of contents, then «Så läser du ett uttag» (seven numbered rules, actions only, each pointing to its primary occurrence), then the format: Dataset structure and indexing (the TAB6471 stride example), a field table,extensionper variable with PX keywords in parentheses, rootextensionandextension.px,status/note/link, what json-stat2 does not carry, tools. Rules come first and the format sections only describe; counts and verification dates go toDEVLOG.md. SCB differs from SSB on mandatory notes: it sets them at three levels — rootnoteMandatory, per variabledimension.{var}.extension.noteMandatory(TAB6471Alder) and per valuecategoryNoteMandatorykeyed value code → index (TAB638Region{"0140": {"1": true}}) — andlink.relatedappears in data responses too, whiledescribedbycarries plain text, not URNs. Don't port SSB's «never set per variable» text heremcp-tools.md— mapping betweenpxweb-mcpMCP tools (@jarib/pxweb-mcp) and API endpoints, the--urlcaveat (the server defaults to SSB), limitations (languageonlyno/en, lossysearch_tables, nooutputFormatParams), and the finding thatoutputValues/output_valueshas no effect at SCB. Facts are version-bound — re-verify when the package ships a new major versionoutput-formats.md(since 0.12.0) — order: «Till Excel» → CSV →outputFormatParams→heading/stub. Keep the heading «Till Excel»:SKILL.mdSteg 4 and Steg 5 point to it by name, and it names the user's goal rather than the answer, so it survives a change of advice. Today it recommends csv (semicolon,UseTexts, Latin-1, decimal point). xlsx is deliberately not described: SCB's xlsx stores every data cell as text (t="s", decimal point even withlang=sv) and some tables answer 500 with an empty body (TAB6596 and TAB5737, 2026-10-27), while SSB and Latvia, on the same software, give numeric cells. The maintainer mailed SCB on 2026-10-28 and asked that the skill say nothing about it meanwhile. To check whether SCB has fixed it —0non-text cells means still broken; SSB 13760 gives 11:curl -s -g -o /tmp/t.xlsx -w '%{http_code}\n' 'https://statistikdatabasen.scb.se/api/v2/tables/TAB6471/data?valueCodes[Region]=0180&valueCodes[Alder]=TotSA&valueCodes[Kon]=1,2&valueCodes[ContentsCode]=000007SF&valueCodes[Tid]=top(2)&outputFormat=xlsx&outputFormatParams=UseTexts' unzip -p /tmp/t.xlsx xl/worksheets/sheet1.xml | grep -o '<\(x:\)\?c [^>]*>' | grep -vc 't="s"'When it is fixed: replace the body of «Till Excel» with the xlsx recipe (as in SSB's «xlsx: anbefalt til Excel», verified against SCB), add an xlsx URL the checker runs, write a CHANGELOG line, and update the «xlsx data cells» row (SCB: text, 500) in
pxwebapi-v2-generic-skill/references/api-details.md— generic-v2 has no checker, so nothing else will flag it. Then the two xlsx sentences further down in this file (under «Facts verified on one installation» and in «Differences to keep in mind»). Deliberately not ported from SSB: parquet (SCB does not serve it) and Power Query (maintainer, 2026-10-27)search-syntax.md— Lucene query parser reference for/tables?query=, plus the default-pageSize-is-20 trap. Swedish term choice and the non-Lucene parameters (pastDays,includeDiscontinued) belong inSKILL.mdSteg 2, not heretroubleshooting.md(since 0.12.0) — the lookup from an error to its cause: onetitletable with an HTTP column (Non-existent tableis 404 from/tables/{id}and/metadata, but 400 from/data), then the errors that carry notitle— 404 with an HTML page (URL too long), curl «bad range», 429, 500 with an empty body, 503. The rule lives inSKILL.mdas one line plus a pointer; this file holds the diagnosis. Keep the heading «För många celler» —SKILL.mdSteg 4 points to it by name. Write failure examples as fragments (valueCodes[Tid]=2025M01,2025M01) or paths without host, never as full URLs:check_examples.pyGETs every full SCB URL and requires 200. There is no/configsection: its fields already stand inSKILL.md(endpoint table, Licens, Språk, Steg 4), and the rate-limit fields are under 429
The SCB skill is still sparser than
ssb-pxwebapi-v2: codelist syntax and filter expressions live inline inSKILL.md, each stated once; output formats and troubleshooting moved toreferences/in 0.12.0. There is nocommon-tables.md— SCB table IDs (TAB6471,TAB6596) appear only in the worked examples.CHANGELOG.mdandDEVLOG.md— two logs for two readers, both in Swedish.CHANGELOG.mdships in the zip and tells users what is different in the answers: a few bullets per version, no sweep counts, no sibling checks.DEVLOG.mdis the maintainer's record and is not shipped: what changed, what was verified live and when, and every sibling-check outcome. It is the oldCHANGELOG.md, split off on 2026-10-05. Every version appears in both. TheCHANGELOG.mdheader links toDEVLOG.mdby full GitHub URL, because a relative link is dead inside the zip.evals/eval-scenarios.md— maintainer-internal behavioural fixtures: typical user questions with the expected table ID and endpoint sequence, success criteria stated as form, never as a concrete figure. Run via theskill-creatorskill after larger edits — as actual runs with tools, not read-throughs. Catches routing regressions (TAB5737 instead of TAB6596, TAB638 instead of TAB6471); the checker catches factual ones. The run log at the bottom of that file records what each scenario found — keep appending to it.evals/trigger-eval.json— trigger fixtures for the frontmatterdescription: 10 queries in skill-creator'srun_eval.pyformat (query,should_trigger, plusidand the expectedroute), 6 that should trigger and 4 near-misses (SSB, Riksbanken, Finland, data already supplied). Run it asssb-pxwebapi-v2-skill/CLAUDE.mddescribes (patchedrun_eval.py, neutral cwd), with@jarib/pxweb-mcp --url https://statistikdatabasen.scb.se/api/v2connected aspxweb-scbthrough a session-only--mcp-configand the user'spxweb-ssbhidden. Results, with model and date, go inDEVLOG.md.docs/— user-facing but deliberately outside the zip: the skill map, in Swedish.skillkarta-arbetsflode.svg(Steg 1–6, the endpoints each step calls, which calls are HTTP-only and not inpxweb-mcp, the/dataresponse as the only source of numbers) andskillkarta-kontroll-och-paketering.svg(whatcheck_examples.pychecks against the live API, the zip build) are hand-drawn and are the only copy of each drawing:skillkarta.htmlwraps them with<img>and prose. Each SVG carries its own<style>and an opaque background, since GitHub serves it as an image and no page CSS or web font reaches it — size text for wide fallback fonts like DejaVu Sans. Both name the version they were drawn from;check_examples.pyreads onlySKILL.mdandreferences/, so nothing checksdocs/. The siblings'docs/use the same layout.scripts/,evals/,.github/(repo root) — repo-internal tooling, deliberately excluded from the distribution.
Editing guidance
- Preserve the bilingual (Swedish primary, English secondary) trigger surface in
SKILL.mdfrontmatter — removing keywords will cause the skill to stop firing for real user queries. - The API base URL and endpoint table in
SKILL.mdare the canonical contract; if an endpoint is added/changed upstream, updateSKILL.md. - Examples should use real, currently-published SCB table IDs. Every v2 table ID is
TAB+ digits (4 286 of 4 286, 2026-10-27);BefolkningNyis a v1 name and gives 404Non-existent tablein v2, sotroubleshooting.mdpoints to pxapiconverter. Tables are renamed/retired more often than IDs suggest. discontinuedis not an aliveness test, and this bit the skill. SCB freezes a table and continues the series in a new one without ever setting the flag. Through v0.10.0 the main worked example used TAB638, which stopped at 2024 (nodiscontinuedfield, last updated 2025-02-21) while the live series moved to TAB5557 (annual 2025) and TAB6471 (monthly, 2025M01–). Two independent eval runs caught it;check_examples.pynever did, because the table answers 200. The checker now also compareslastPeriodagainst today (staleness()) and fails an example table that is more than a year, eight months, four quarters or 26 weeks behind. When an example fails that way, find the successor table rather than raising the allowance.- For example URLs/queries, run
check_examples.py. Common 400 causes: missing required variable (TidandContentsCodeare never eliminable, but which others are is per table —Alderis eliminable in TAB638 and mandatory in TAB6471), a codelist used with the table's ordinary codes instead of the codelist's own (agg_RegionKommungrupp2023-wants2023_A1, not0180—Non-existent value), wrong time format for the table'stimeUnit(weekly is2026V30at SCB, notW). - Use
valueCodes(camelCase) consistently in GET examples — matches the OpenAPI spec and the POST body shape, even though the API is case-insensitive. - Region codes for Sweden are 4-digit SKR codes (e.g.
0180Stockholm); first two digits are the län code (01*= all Stockholm-län municipalities). The "Riket" total is00, and it is theeliminationValueCodeforRegion— visible only in data responses that include it. - From reference year 2025 SCB adds CKM noise to population statistics (Cell Key Method: a small controlled random perturbation, so reported totals are not always the sum of their parts, and the uncertainty compounds when you sum values yourself). It arrives as a mandatory note on the affected tables, and it constrains the arithmetic Steg 5 invites. Keep the Steg 5 bullet that says so; if a future example uses a pre-2025 table, the caveat does not apply to it.
- Facts verified on one installation are written as facts about that installation. SCB sets no
role.geo(SSB does); SCB announces its rate limit in/configand inX-Rate-Limit-*headers — a different spelling from SSB'sx-ratelimit-*, which is why an earlier grep concluded "no headers"; SCB serves noparquet(SSB does). Each of these has been written as a universal rule in some sibling at some point. SSB's «xlsx: anbefalt til Excel» is the next candidate: SCB's xlsx has text data cells where SSB's are numeric, so don't port it (seeoutput-formats.mdabove). When porting a fix fromssb-pxwebapi-v2, verify it against SCB first — the rate-limit fix from SSB 1.5.0 would have introduced an error here. - The Dataintegritet — grundregeln section at the top of
SKILL.mdoutranks everything else in the skill: never state a number not fetched from the API in that conversation, never blend other sources, never interpolate. Don't weaken, shorten or relocate it — the rest of the workflow assumes it. It mirrors the same section inssb-pxwebapi-v2(Norwegian),generic-pxweb-v2-skillandgeneric-pxweb-v1-skill(English); a change to the rule belongs in all four. The mandatory-notes bullet is mirrored here, and keeping the API's decimals sits inside «Märk dina egna beräkningar»; SSB's bullets on verifying variable codes and flagging provisional figures are not mirrored. - Answers must comment only on the numbers fetched in the query — never fetch and blend in data from other sources (Riksbanken, Eurostat, web search); refer the user onward instead. The rule lives in Dataintegritet; Steg 5 and Fallgropar point to it rather than repeating it.
- Worked examples show form, not figures:
{N},{år}/{year}in the «→» lines. A number that stands in the instruction text is a number a model can repeat when the API fails. Placeholders go outside the JSON blocks so the checker's brace-counting is untouched.
Release checklist (every content change)
- Bump
metadata.versioninSKILL.mdfrontmatter (semver; stay below 1.0.0 while the rootREADME.mdmarks the skill beta). A version that isn't bumped lies about copies being current. - Add a
DEVLOG.mdentry (Swedish) — what changed, what was verified live, on what date. Then add the user entry inCHANGELOG.md(Swedish), derived from it: what is different in the answers, in a few bullets, with corrections marked Rättat:. Same version and date in both files. - Rebuild the zip with
scripts/build_zip.sh— thezip-syncCI job fails otherwise. - If you added a file to
references/, update the file tree inREADME.mdtoo (hand-maintained;build_zip.shglobsreferences/*.mdso the file ships either way). - If a factual claim changed, do the sibling check below and record its outcome in
DEVLOG.md, including when the answer is "does not apply". It stays out ofCHANGELOG.md, which is about this skill's answers. - If you changed a step, an endpoint, a limit or the checker, redraw the matching SVG in
docs/. Neither is in the zip, sozip-syncwill not catch them drifting.
The zip and the README file tree contain user-facing files only: SKILL.md, README.md, CHANGELOG.md, references/, plus LICENSE in the zip. Never add scripts/, evals/, CLAUDE.md or DEVLOG.md to either; docs/ is user-facing and in the README tree, but stays out of the zip (see Layout).
LICENSE (MIT) lives in the repo root and covers the whole repo; build_zip.sh copies it into the package because MIT requires the notice to travel with every copy, and the zip is the copy that gets handed out. Don't add a per-skill LICENSE — edit the root one, and rebuild all six zips when it changes (every zip-sync workflow has LICENSE in its paths: filter). SKILL.md frontmatter carries license: MIT. LICENSE has complete terms (the optional Agent Skills field — keep it short, it names the file beside SKILL.md in the zip); never put licence text in the body, which is loaded on every trigger.
Related sibling skills
ssb-pxwebapi-v2— Norway's SSB, same PxWebApi v2 shape, deeper (Klass/VarDok URNs,agg_KommFylker/agg_KommSummerwithF-/K-prefixes, common-tables index, more reference files). When fixing a bug in one, check whether the other needs the same fix — and verify against the other installation before porting (see "Facts verified on one installation" above).generic-pxweb-v2-skill— vendor-neutral v2. Response-side findings that hold on both installations (eliminationValueCodeonly in data responses,outputValuesnot load-bearing,role.geooptional) belong there too.generic-pxweb-v1-skill— PxWebApi v1, which SCB still runs alongside v2 atapi.scb.se/OV0104/v1/doris/. The request side does not transfer at all; only json-stat2 semantics are shared.
Differences to keep in mind between SCB and SSB:
- Different base URLs (SCB:
statistikdatabasen.scb.se/api/v2; SSB:data.ssb.no/api/pxwebapi/v2) and default language (SCBsv, SSBno) - SCB uses 4-digit SKR codes; SSB uses 4-digit kommunekoder + special prefixes (
F-,K-) for aggregation codelists. SCB's aggregation codelists carry their own code sets (2023_A1…) - SSB has well-documented Klass/VarDok URN systems exposed via
link.describedby; SCB metadata is sparser - SCB:
maxDataCells150 000, rate limit 30 calls / 10 s in/configplusX-Rate-Limit-*headers, noparquet, norole.geo. SSB: 800 000,x-ratelimit-*headers only,parquet,role.geoset - Errors, measured on both 2026-10-27/28. Same: the 400
titlestrings,Non-existent tableas HTTP 400 from/data, validation errors asapplication/problem+jsonwitherrors, and a GET URL over ~2 100 characters giving 404 with an HTML page. Different: xlsx data cells are text at SCB, numeric at SSB;GET /codelists/{id}ignores case at SCB and gives 500 at SSB; a repeated value code gives 500 at SCB inTidandContentsCodebut is silently deduplicated inRegion,AlderandKon(TAB6471), while SSB gives 500 inRegiontoo
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

