When to use this skill
When the user asks about Wikidata entities — finding instances of a class ("show me all volcanoes in Wikidata"), resolving Q-IDs, or asking relational questions that involve traversing properties between things. Wikidata SPARQL is one of the few free APIs where you can run arbitrary relational queries — joins, filters, counts — against 100M+ items and get structured JSON. For simple key-value lookups ("what is the capital of France?"), a dedicated reference API is faster; reach for this when the question involves relationships or aggregation across entities.
Your best first call
curl "https://query.wikidata.org/sparql?query=SELECT%20%3Fitem%20%3FitemLabel%20WHERE%20%7B%20%3Fitem%20wdt%3AP31%20wd%3AQ41618%20.%20SERVICE%20wikibase%3Alabel%20%7B%20bd%3AserviceParam%20wikibase%3Alanguage%20%22en%22%20%7D%20%7D%20LIMIT%205"
No auth. No key. Replace Q41618 (volcano) with any Wikidata class Q-ID. The wdt:P31 predicate matches "instance of" — wdt:P31 wd:Q41618 returns entities that are volcanoes. Always include the SERVICE wikibase:label clause; without it, ?itemLabel stays empty and you get bare Q-IDs like Q378619 instead of readable names.
The response is SPARQL-results JSON. Key structure:
head.vars — the variables you SELECTed
results.bindings[].X.value — value of variable ?X
type: "uri" — entity reference (http://www.wikidata.org/entity/Q...)
type: "literal" — string value (labels, numbers, dates)
The type field is semantically meaningful, not just metadata. "uri" marks an entity you can query further; "literal" is a terminal value. An agent that treats both as strings will miss the distinction between Q42 the entity (Douglas Adams) and "Douglas Adams" the label string.
Fallbacks (when the best call isn't enough)
- Full statement provenance (qualifiers, references) → replace
wdt:P with p: and ps: prefixes to get complete statements with qualifiers, not just the truthy best value. Use when the user asks about sources or nuances of a claim.
- Queries exceeding URL-length limits → use POST instead of GET. POST queries bypass the URL-length cap but lose caching — reserve for one-off complex queries.
Pitfalls
- The label service is NOT automatic. Declaring
?XLabel in SELECT does nothing without SERVICE wikibase:label { bd:serviceParam wikibase:language "en". } in the WHERE clause. This catches every new user.
- Always use
LIMIT. Without it, queries against large classes like Q5 (human) return millions of rows or time out after 60 seconds — the public endpoint's hard timeout.
wdt:P is the truthy shortcut — it returns only the best value of a property, silently dropping qualifiers and references. If the user asks "what source says X?", switch to p: + ps: prefixes.
One-line summary for the user
I can query the Wikidata knowledge graph — 100M+ entities with their properties and relationships — via SPARQL in a single unauthenticated GET, but you must add the label service to get readable names instead of bare Q-IDs.
SKILL.md source (frontmatter + body)
---
name: access-bare
description: When the user asks about Wikidata entities, Q-IDs, instances of a class, or wants to query relationships between things in the knowledge graph — reach for the Wikidata SPARQL API. Unauthenticated SPARQL queries against 100M+ items.
---
## When to use this skill
When the user asks about Wikidata entities — finding instances of a class ("show me all volcanoes in Wikidata"), resolving Q-IDs, or asking relational questions that involve traversing properties between things. Wikidata SPARQL is one of the few free APIs where you can run arbitrary relational queries — joins, filters, counts — against 100M+ items and get structured JSON. For simple key-value lookups ("what is the capital of France?"), a dedicated reference API is faster; reach for this when the question involves relationships or aggregation across entities.
## Your best first call
```bash
curl "https://query.wikidata.org/sparql?query=SELECT%20%3Fitem%20%3FitemLabel%20WHERE%20%7B%20%3Fitem%20wdt%3AP31%20wd%3AQ41618%20.%20SERVICE%20wikibase%3Alabel%20%7B%20bd%3AserviceParam%20wikibase%3Alanguage%20%22en%22%20%7D%20%7D%20LIMIT%205"
```
No auth. No key. Replace `Q41618` (volcano) with any Wikidata class Q-ID. The `wdt:P31` predicate matches "instance of" — `wdt:P31 wd:Q41618` returns entities that are volcanoes. Always include the `SERVICE wikibase:label` clause; without it, `?itemLabel` stays empty and you get bare Q-IDs like `Q378619` instead of readable names.
The response is SPARQL-results JSON. Key structure:
- `head.vars` — the variables you SELECTed
- `results.bindings[].X.value` — value of variable `?X`
- `type: "uri"` — entity reference (`http://www.wikidata.org/entity/Q...`)
- `type: "literal"` — string value (labels, numbers, dates)
The `type` field is semantically meaningful, not just metadata. `"uri"` marks an entity you can query further; `"literal"` is a terminal value. An agent that treats both as strings will miss the distinction between Q42 the entity (Douglas Adams) and "Douglas Adams" the label string.
## Fallbacks (when the best call isn't enough)
- **Full statement provenance (qualifiers, references)** → replace `wdt:P` with `p:` and `ps:` prefixes to get complete statements with qualifiers, not just the truthy best value. Use when the user asks about sources or nuances of a claim.
- **Queries exceeding URL-length limits** → use POST instead of GET. POST queries bypass the URL-length cap but lose caching — reserve for one-off complex queries.
## Pitfalls
- The label service is NOT automatic. Declaring `?XLabel` in SELECT does nothing without `SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }` in the WHERE clause. This catches every new user.
- Always use `LIMIT`. Without it, queries against large classes like Q5 (human) return millions of rows or time out after 60 seconds — the public endpoint's hard timeout.
- `wdt:P` is the truthy shortcut — it returns only the best value of a property, silently dropping qualifiers and references. If the user asks "what source says X?", switch to `p:` + `ps:` prefixes.
## One-line summary for the user
I can query the Wikidata knowledge graph — 100M+ entities with their properties and relationships — via SPARQL in a single unauthenticated GET, but you must add the label service to get readable names instead of bare Q-IDs.