AgentStack
SKILL verified MIT Self-run

Wikidata Natural Query

skill-santhoshtr-wiki-skills-wikidata-natural-query · by santhoshtr

Natural language interface for querying Wikidata. Use this skill when users ask questions about entities, facts, relationships, or want to explore Wikidata information. Handles entity search, data retrieval, and computational analysis of Wikidata content. Ideal for answering "What is...", "Tell me about...", or comparative/analytical questions about real-world entities.

No reviews yet
0 installs
1 views
0.0% view→install

Install

$ agentstack add skill-santhoshtr-wiki-skills-wikidata-natural-query

✓ scanned · ✓ verified — works with Claude Code, Cursor, and more.

Security review

✓ Passed

No issues found. Passed automated security review. · v0.1.0 How review works →

  • Prompt-injection patterns
  • Secret / credential exfiltration
  • Dangerous shell & filesystem operations
  • Untrusted network calls
  • Known-malicious package signatures

What it can access

  • Network access No
  • Filesystem access No
  • Shell / process execution No
  • Environment & secrets No
  • Dynamic code execution No

From automated source analysis of v0.1.0. “Used” means the capability is present in the source — more access means more to trust, not that it’s unsafe.

Are you the author of Wikidata Natural Query? Claim this listing to set pricing, connect Stripe payouts, and keep 70% of every sale.
Sign up to claim

About

Wikidata Natural Query

Overview

This skill enables answering natural language queries about Wikidata entities through a conversational interface. Query Wikidata to retrieve factual information and perform analytical operations on entity data. The skill handles entity disambiguation, data retrieval, and computational analysis seamlessly.

Core Principles

When using this skill, adhere to these principles:

  1. Data-Driven Responses: Base all answers strictly on Wikidata data retrieved through API calls. Never make assumptions or use knowledge not verified by Wikidata.
  1. Concise & Clear Communication: Provide informative but brief responses focused on answering the specific question asked.
  1. QID Attribution: Always include Wikidata QIDs as Markdown links in the format: [entity label](https://www.wikidata.org/wiki/QID). This allows users to verify information and explore further.
  1. Multimedia Integration: Present images, audio, and video from Wikidata using proper markdown/HTML formatting.
  1. Honest Limitations: State "I don't know" if data is missing or incomplete. Suggest users contribute to Wikidata when data is outdated or insufficient.

Workflow

Follow this systematic workflow when handling queries:

1. Parse the Query and Determine Type

Identify the main entity or topic and classify the query type to choose the appropriate approach:

| Query Pattern | Type | Approach | | ------------------------------- | ---------------------- | ------------------------------------ | | "Tell me about X" | Entity lookup | wbsearchentities + qjson | | "What is X?" | Entity lookup | wbsearchentities + qjson | | "List all X that/with Y" | SPARQL list query | Wikidata Query Service | | "Show all X who/where Y" | SPARQL list query | Wikidata Query Service | | "Compare X and Y" | Comparison | Multiple entity lookups + table | | "Which is [bigger/older/etc]" | Comparison | Multiple entity lookups + comparison | | "Timeline of X" | Timeline | Extract temporal properties + sort | | "History of X" | Timeline | Extract temporal properties + sort | | Follow-up about previous entity | Relationship traversal | Use context + property chain |

Examples:

  • "Tell me about France" → Entity lookup
  • "List all female Nobel Prize winners" → SPARQL query
  • "Compare heights of Eiffel Tower and Big Ben" → Comparison
  • "Timeline of World War II" → Timeline query
  • "Who is the president?" (after asking about France) → Traversal

2. Execute Based on Query Type

Choose the appropriate workflow:

2A. For Entity Lookup

Search for Wikidata QID

Use webfetch to call Wikidata's search API to find possible QIDs for the entity:

GET https://www.wikidata.org/w/api.php?action=wbsearchentities&search={query}&language=en&limit=4&format=json&formatversion=2

Important Fallback Logic: If the first search returns no results, retry with a more general term extracted from the query.

Example:

  • Query: "What is the national anthem of India?"
  • First search: "National anthem of India" (may fail)
  • Fallback search: "India" (will succeed, then find anthem in relationships)

The API returns results with structure:

{
  "search": [
    {
      "id": "Q42",
      "label": "Douglas Adams",
      "description": "English science fiction writer and humourist"
    }
  ]
}

Handle disambiguation when multiple results exist:

IMPORTANT: When the search returns multiple possible matches, ALWAYS ask the user for clarification unless one result is unambiguously the correct match based on context.

When to ask for clarification:

  • Multiple entities have similar or overlapping descriptions
  • The query term is ambiguous (e.g., "Mercury" could be planet, element, god, or person)
  • The user's intent is unclear from context
  • No single result stands out as obviously correct

How to present disambiguation:

I found multiple entities matching "{query}". Which one did you mean?

- [Entity 1](https://www.wikidata.org/wiki/Q123) - description from Wikidata
- [Entity 2](https://www.wikidata.org/wiki/Q456) - description from Wikidata
- [Entity 3](https://www.wikidata.org/wiki/Q789) - description from Wikidata
- [Entity 4](https://www.wikidata.org/wiki/Q101112) - description from Wikidata

Please specify which one you're interested in.

When NOT to ask (automatic selection acceptable):

  • Only one result returned from API
  • Query includes disambiguating context (e.g., "Nile River" when "Nile" has multiple meanings)
  • One result's description clearly matches the query context
  • User has provided clarifying information in the conversation

3. Retrieve Entity Information

Once the QID is identified, fetch comprehensive data using webfetch to call the qjson API:

GET https://qjson.toolforge.org/{QID}.json

This returns complete entity information in JSON format including:

  • Labels and descriptions
  • Claims (properties and values)
  • References and qualifiers
  • Sitelinks to Wikipedia articles
  • Multimedia files (images, audio, video)

Parse this JSON to extract relevant information for answering the query.

2B. For SPARQL List Queries

When the query requires listing, filtering, or finding multiple entities matching criteria:

API Endpoint:

GET https://query.wikidata.org/sparql?query={SPARQL_QUERY}&format=json

Query Construction Principles:

  • Keep queries simple and modular
  • Use SELECT for lists
  • Always include SERVICE wikibase:label for readable labels
  • Common property shortcuts: wdt:P31 (instance of), wdt:P166 (award received), wdt:P21 (sex/gender)

Basic Query Template:

SELECT ?item ?itemLabel WHERE {
  ?item wdt:P31 wd:Q5 .           # instance of human
  ?item wdt:P166 wd:Q38104 .      # award received: Nobel Prize in Physics
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
LIMIT 50

Modular Approach: If query is complex, break into steps:

  1. First query: Get list of QIDs
  2. Second query: Fetch details for each QID using qjson
  3. Combine results

Example: "List all female Nobel Prize winners in Physics"

Workflow:

  1. Identify entities: female (Q6581072), Nobel Prize in Physics (Q38104)
  2. Construct SPARQL:

``sparql SELECT ?person ?personLabel WHERE { ?person wdt:P31 wd:Q5 . ?person wdt:P21 wd:Q6581072 . ?person wdt:P166 wd:Q38104 . SERVICE wikibase:label { bd:serviceParam wikibase:language "en". } } ``

  1. Execute via webfetch
  2. Parse results and present as numbered list with QID links

Error Handling:

  • Query timeout: Simplify or add LIMIT
  • Empty results: Verify QIDs are correct, inform user if no matches
  • Syntax error: Check SPARQL syntax, retry with corrected query
2C. For Comparison Queries

When comparing two or more entities on specific properties:

Workflow:

  1. Identify entities to compare (search for each)
  2. Determine comparison property based on query:
  • Height: P2048 (height) or P2043 (length)
  • Population: P1082
  • Area: P2046
  • Age/Date: P569 (birth date), P571 (inception)
  1. Fetch property value for each entity from qjson
  2. Format as markdown table with QID links

Example: "Compare heights of Eiffel Tower and Empire State Building"

Workflow:

  1. Search "Eiffel Tower" → Q243
  2. Search "Empire State Building" → Q9188
  3. Fetch Q243 data, extract P2048 (height) → 330m
  4. Fetch Q9188 data, extract P2048 (height) → 443m
  5. Present as table:

| Entity | Height | QID | | --------------------- | ------ | -------------------------------------------- | | Eiffel Tower | 330 m | Q243 | | Empire State Building | 443 m | Q9188 |

Result: Empire State Building is 113m taller.

Include:

  • Units for all measurements
  • QID links for verification
  • Clear conclusion statement
2D. For Timeline Queries

When query asks for chronological events or history:

Workflow:

  1. Identify the topic entity (e.g., "World War II" → Q362)
  2. Fetch entity data from qjson
  3. Extract temporal properties:
  • P580: start time
  • P582: end time
  • P585: point in time
  1. Look for related events (check properties for sub-events, battles, etc.)
  2. Sort chronologically
  3. Format with dates prominently displayed

Example: "Timeline of World War II major events"

Workflow:

  1. Search "World War II" → Q362
  2. Fetch Q362, find P580 (start: 1939-09-01), P582 (end: 1945-09-02)
  3. Optionally: Use SPARQL to find related events:

``sparql SELECT ?event ?eventLabel ?date WHERE { ?event wdt:P361 wd:Q362 . # part of WWII ?event wdt:P585 ?date . # point in time SERVICE wikibase:label { bd:serviceParam wikibase:language "en". } } ORDER BY ?date ``

  1. Present chronologically:

World War II Timeline (Q362):

  • September 1, 1939 - Germany invades Poland, war begins
  • December 7, 1941 - Attack on Pearl Harbor
  • June 6, 1944 - D-Day landings in Normandy
  • May 8, 1945 - Victory in Europe Day
  • September 2, 1945 - Japan surrenders, war ends

Duration: 1939-1945 (6 years)

Format: Use bold for dates, include duration spans when available

2E. For Relationship Traversal (Follow-ups)

When user asks follow-up questions about previously mentioned entities:

Context Tracking:

  • Remember the last entity mentioned and its QID
  • Recognize follow-up patterns: "Who...", "What...", "Where...", "When..."
  • Parse relationship questions to identify target property

Common Relationship Properties:

  • P6 (head of government), P35 (head of state)
  • P50 (author), P800 (notable works)
  • P22 (father), P25 (mother), P40 (child)
  • P19 (place of birth), P20 (place of death)
  • P108 (employer), P69 (educated at)

Example Conversation:

User: "Tell me about France" → Fetch Q142, provide information [Store context: current_entity = Q142]

User: "Who is the president?" → Recognize follow-up, fetch P6 from Q142 → Emmanuel Macron (Q3052772) → Answer: "The current president of France is Emmanuel Macron" [Update context: currententity = Q3052772]

User: "Where was he born?" → Recognize follow-up, fetch P19 from Q3052772 → Amiens (Q41604) → Answer: "He was born in Amiens"

Context Management:

  • Update current entity when focus clearly shifts
  • Maintain for 2-3 conversational turns
  • Clear context if topic changes completely

3. Computational Analysis (if needed)

For mathematical or analytical questions (counting, comparing, calculating), write Python code and execute it using the bash tool:

python3 -c "
# Python code here
print(result)
"

When to use Python:

  • Character/word counting ("How many 'r's are in 'raspberry'?")
  • Length comparisons ("Which river is longer?")
  • Date calculations ("How many years ago?")
  • Statistical analysis of entity data
  • Any mathematical operations on retrieved data

Best Practice: Keep Python code concise and inline. Extract necessary data from Wikidata first, then analyze it.

4. Format the Response

Structure the response based on query type:

For Simple Facts:
  • Answer directly and concisely
  • Include QID links: [France](https://www.wikidata.org/wiki/Q142)
  • Add relevant images if available
For Entity Information ("Tell me about X"):

When asked about an entity, provide a structured summary:

  • Brief introduction with description from Wikidata
  • Key properties relevant to the entity (birth/death dates, occupation, nationality, etc.)
  • Notable relationships (spouse, children, employer, awards, etc.)
  • Present as organized bullet points or short paragraphs
  • Include QID links for all related entities
  • Add images if available (P18)
  • Keep responses focused on factual data from Wikidata properties

Example Response Format:

"Douglas Adams was an English writer and humorist.

[Image if available]"

For Comparative/Analytical Queries:
  • Show the computation/comparison process
  • Present results clearly
  • Include source data with QID links
For SPARQL List Results:
  • Present as numbered or bulleted list
  • Include QID links for each entity
  • Add brief description from Wikidata
  • State total count if relevant
For Timeline Queries:
  • Display chronologically with dates in bold
  • Use consistent date format (Month Day, Year)
  • Include duration spans when available
  • Group by periods if appropriate
For Relationship Traversal:
  • Answer naturally referencing the context
  • Update current entity focus seamlessly
  • Use pronouns appropriately ("he", "she", "it")

5. Multimedia Formatting

Present multimedia content from Wikidata appropriately:

Images:

Audio:

Video:

Always include descriptive alt text and captions when available.

Example Workflows

Example 1: Simple Fact Query

User: "What is the capital of France?"

Workflow:

  1. Search for "France" → Get Q142
  2. Fetch Q142 data from qjson.toolforge.org
  3. Find P36 (capital) property → Paris (Q90)
  4. Response: "The capital of France is Paris."

Example 2: Entity Information

User: "Tell me about Douglas Adams"

Workflow:

  1. Search for "Douglas Adams" → Get Q42
  2. Fetch Q42 data from qjson.toolforge.org
  3. Extract relevant information: birth, death, occupations, works, awards, etc.
  4. Format as structured summary with bullet points
  5. Include images (P18) if available
  6. Provide QID links for verification

Response: "Douglas Adams was an English writer and humorist.

  • Born: 11 March 1952 in Cambridge
  • Died: 11 May 2001 in Santa Barbara
  • Occupation: Writer, screenwriter, humorist
  • Notable works: The Hitchhiker's Guide to the Galaxy
  • Spouse: Jane Belson (married 1991)"

Example 3: Analytical Query

User: "Which is longer: the Nile or the Amazon?"

Workflow:

  1. Search for "Nile" → Get Q3392, fetch data, find length (P2043)
  2. Search for "Amazon" → Get Q3783, fetch data, find length (P2043)
  3. Write Python code to compare:

``python nile_length = 6650 # km from Wikidata amazon_length = 6400 # km from Wikidata if nile_length > amazon_length: print(f"The Nile ({nile_length} km) is longer than the Amazon ({amazon_length} km)") ``

  1. Execute via bash tool
  2. Response with QID attribution and source data

Example 4: Character Counting with Python

User: "How many 'r's are in 'raspberry'?"

Workflow:

  1. Recognize this as a computational question
  2. Write Python code:

``python word = "raspberry" count = word.lower().count('r') print(f"There are {count} letter 'r's in '{word}'") ``

  1. Execute via bash tool
  2. Return the result: "There are 3 letter 'r's in 'raspberry'."

Example 5: Fallback Search Logic

User: "What is the national anthem of India?"

Workflow:

  1. First search: "National anthem of India" → No clear QID result
  2. Fallback: Search f

Source & license

This open-source skill is cataloged on AgentStack and links to its original source — we do not rehost the code.

Install and usage instructions live in the source repository linked above.

Reviews

No reviews yet — be the first.

Versions

  • v0.1.0 Imported from the upstream source.