sparql-expert
Skill78 starsChanged 7 days agoApache-2.0View on GitHub
Expert system for SPARQL 1.1 and SPARQL-star query generation, validation, and execution. Handles differences between GraphDB, Stardog, Fuseki, and local rdflib graphs. Use when querying knowledge graphs or debugging SPARQL.
In this repository38 other files it gives its agents.
- AGENTS.mdAGENTS.md
- explorations/AGENTS.mdAGENTS.md
- adhdSkill
- atom-reactivity-specialistSkill
- browser-qa-loopSkill
- closeoutSkill
- codex-findingsSkill
- crispenSkill
- effect-first-developmentSkill
- exploreSkill
- grillingSkill
- grill-meSkill
- grill-with-docsSkill
- jsdoc-annotation-specialistSkill
- motion-evidence-reviewSkill
- onepassword-secret-refsSkill
- ontology-architectSkill
- ontology-conceptualizerSkill
- ontology-curatorSkill
- ontology-foundational-auditorSkill
- ontology-mapperSkill
- ontology-requirementsSkill
- ontology-scoutSkill
- ontology-validatorSkill
- operator-handoffSkill
- orchestrateSkill
- plasma-sensitive-entrySkill
- portlessSkill
- qa-session-opsSkill
- quality-review-fix-loopSkill
- reflectSkill
- remote-development-agentsSkill
- schema-first-developmentSkill
- shadcnSkill
- teachSkill
- turborepoSkill
- unslopSkill
- yeetSkill
The file
Show its rules and text
We split this skill into the rules it gives an agent
22 rules. About 0 are common, 10 are distinctive, and 12 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈10
Distinctive · estimate
This author's own choices. Worth a look.
12
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 30
Read these files from _shared/ before beginning work:
- Distinctive: line 48
Before writing the query:
- Very specific: line 49
Read _shared/namespaces.json for correct prefixes
- Distinctive: line 50
If targeting an endpoint, check available named graphs
- Distinctive: line 51
If querying a specific ontology, check its class/property structure
- Distinctive: line 56
ALWAYS include PREFIX declarations for every prefix used
- Very specific: line 57
Use LIMIT for exploratory queries (default: 100)
- Distinctive: line 58
Add comments for complex patterns
- Very specific: line 59
Use FILTER(!isBlank(?x)) to exclude blank nodes when counting
- Very specific: line 181
Add selective anchors and LIMIT when exploring transitive paths.
- Distinctive: line 182
Prefer bounded patterns for production queries when possible.
- Very specific: line 251
Always use LIMIT for exploratory queries
- Very specific: line 252
Avoid leading wildcards in FILTER regex (regex(?var, ".*pattern")) — they prevent index usage
- Very specific: line 254
Use property paths (rdfs:subClassOf+) sparingly on large graphs
- Very specific: line 255
Check OPTIONAL patterns for Cartesian products
- Very specific: line 256
Prefer FILTER EXISTS / FILTER NOT EXISTS over subqueries
- Very specific: line 257
Use VALUES clause for parameterized queries
- Distinctive: line 258
Place most selective triple patterns first in the WHERE clause
- Very specific: line 262
Missing PREFIXes: Every CURIE must have a corresponding PREFIX declaration.
- Distinctive: line 264
No LIMIT on exploration: Always limit exploratory queries.
- Distinctive: line 266
SPARQL UPDATE on production: Never execute UPDATE/DELETE against production endpoints.
- Distinctive: line 270
Ignoring blank nodes: Always filter blank nodes when counting or listing named entities.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill 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
SPARQL Expert
Role Statement
You are responsible for generating, validating, and executing SPARQL queries across different backends. You handle dialect differences between triple stores, write correct PREFIX declarations, validate syntax before execution, and optimize query performance. You serve all other skills that need SPARQL queries — CQ test generation, anti-pattern detection, coverage metrics, and ad hoc data exploration.
When to Activate
- User mentions "SPARQL", "query", or "knowledge graph"
- User wants to extract data from an ontology or triple store
- User wants to debug or optimize a SPARQL query
- Another skill needs a SPARQL query generated or executed
Shared Reference Materials
Read these files from _shared/ before beginning work:
_shared/namespaces.json— canonical prefix-to-IRI map (always include correct PREFIX declarations)_shared/methodology-backbone.md— lifecycle context (cross-cutting)
Core Workflow
Step 1: Analyze Intent
Determine:
- Query type: SELECT, CONSTRUCT, ASK, DESCRIBE
- Target: Local file (ROBOT/rdflib), SPARQL endpoint, or oaklib adapter
- Purpose: Exploration, testing, reporting, or data extraction
- Constraints: Result size limits, performance requirements
Step 2: Schema Lookup
Before writing the query:
- Read
_shared/namespaces.jsonfor correct prefixes - If targeting an endpoint, check available named graphs
- If querying a specific ontology, check its class/property structure
Step 3: Draft Query
Rules:
- ALWAYS include PREFIX declarations for every prefix used
- Use
LIMITfor exploratory queries (default: 100) - Add comments for complex patterns
- Use
FILTER(!isBlank(?x))to exclude blank nodes when counting - SPARQL matching is homomorphism-based: two variables may bind to the same node
unless explicitly constrained (use
FILTER(?x != ?y)when required) - For RDF-star: embedded triples are NOT asserted by default in GraphDB
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
# Purpose: {what this query does}
SELECT ?class ?label ?definition
WHERE {
?class a owl:Class ;
rdfs:label ?label .
OPTIONAL { ?class skos:definition ?definition }
FILTER(!isBlank(?class))
}
ORDER BY ?label
LIMIT 100Step 4: Validate Syntax
# Validate via rdflib parser
uv run python -c "
from rdflib.plugins.sparql import prepareQuery
q = '''
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
SELECT ?s WHERE { ?s rdf:type owl:Class }
'''
prepareQuery(q)
print('Valid SPARQL')
"Step 5: Execute
# Via ROBOT (local ontology files)
robot query --input ontology.ttl --query query.sparql --output output.csv
# Via oaklib
uv run runoak -i sqlite:obo:hp query \
"SELECT ?x ?label WHERE { ?x rdfs:label ?label } LIMIT 10"
# Via rdflib (Python)
uv run python -c "
from rdflib import Graph
g = Graph()
g.parse('ontology.ttl', format='turtle')
results = g.query(open('query.sparql').read())
for row in results:
print(row)
"Tool Commands
Common query patterns
Reuse the prefix prologue below with each query. Replace the illustrative
http://example.org/ namespace with the dataset's namespace.
PREFIX : <http://example.org/>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX obo: <http://purl.obolibrary.org/obo/>
# List all classes with labels
SELECT ?class ?label WHERE {
?class a owl:Class ; rdfs:label ?label .
FILTER(!isBlank(?class))
}
# Count classes
SELECT (COUNT(DISTINCT ?class) AS ?count) WHERE {
?class a owl:Class .
FILTER(!isBlank(?class))
}
# Find subclasses of a specific class
SELECT ?sub ?label WHERE {
?sub rdfs:subClassOf :ParentClass ;
rdfs:label ?label .
}
# Find classes missing definitions
SELECT ?class ?label WHERE {
?class a owl:Class ; rdfs:label ?label .
FILTER NOT EXISTS { ?class skos:definition ?def }
FILTER NOT EXISTS { ?class obo:IAO_0000115 ?def }
FILTER(!isBlank(?class))
}
# Property usage statistics
SELECT ?prop (COUNT(*) AS ?usage) WHERE {
?s ?prop ?o .
?prop a owl:ObjectProperty .
}
GROUP BY ?prop
ORDER BY DESC(?usage)Property Path Reference
| Pattern | Meaning | Example | ||
* | Zero or more hops | ?x rdfs:subClassOf* ?y | ||
+ | One or more hops | ?x rdfs:subClassOf+ ?y | ||
| ` | ` | Alternative path | `?x (skos:exactMatch | skos:closeMatch) ?y` |
^ | Inverse property | ?x ^rdfs:subClassOf ?parent | ||
/ | Concatenation | ?x rdfs:subClassOf/rdfs:subClassOf ?gparent |
Common caution points:
- Property paths over cyclic graphs can explode result sizes.
- Add selective anchors and
LIMITwhen exploring transitive paths. - Prefer bounded patterns for production queries when possible.
RDF-star patterns
PREFIX : <http://example.org/>
# GraphDB: match asserted triple with metadata
SELECT ?s ?p ?o ?metaValue WHERE {
?s ?p ?o .
<< ?s ?p ?o >> :hasConfidence ?metaValue .
}
# Stardog: edge properties (if enabled)
SELECT ?s ?p ?o ?conf WHERE {
?s ?p ?o .
<< ?s ?p ?o >> :confidence ?conf .
}Federated queries
PREFIX : <http://example.org/>
PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
# Query across multiple endpoints
SELECT ?local ?external WHERE {
?local a :LocalClass .
SERVICE <http://dbpedia.org/sparql> {
?external a dbo:Thing ;
rdfs:label ?label .
}
}Entailment Regime Awareness
Query results depend on whether inference is applied:
- Local/raw file queries typically return only asserted triples.
- Reasoned artifacts or reasoner-backed endpoints may return inferred triples.
- CQ interpretation must state which entailment regime is assumed (asserted-only vs inferred).
Outputs
This skill produces:
| Artifact | Location | Format | Description |
| Query files | sparql/{name}.sparql | SPARQL | Stored, validated queries |
| Query results | {context-dependent} | CSV/TSV/JSON | Query output |
Handoff
Receives from: Any skill that needs SPARQL queries generated or executed
Passes to: Requesting skill (query files and/or results)
Handoff checklist:
- Query syntax is validated
- PREFIX declarations are complete and correct
- Results are in the requested format
- Query is saved to
sparql/if reusable
Performance Tips
- Always use
LIMITfor exploratory queries - Avoid leading wildcards in
FILTER regex(regex(?var, ".*pattern")) — they prevent index usage - Use property paths (
rdfs:subClassOf+) sparingly on large graphs - Check
OPTIONALpatterns for Cartesian products - Prefer
FILTER EXISTS/FILTER NOT EXISTSover subqueries - Use
VALUESclause for parameterized queries - Place most selective triple patterns first in the WHERE clause
Anti-Patterns to Avoid
- Missing PREFIXes: Every CURIE must have a corresponding PREFIX
declaration. Use
_shared/namespaces.jsonas the source. - No LIMIT on exploration: Always limit exploratory queries. An unbounded SELECT against a large graph can timeout or crash.
- SPARQL UPDATE on production: Never execute UPDATE/DELETE against production endpoints. (Safety Rule #8)
- Assuming RDF-star assertion: In GraphDB,
<< s p o >>does NOT assert the triple. You must also states p o .separately. - Ignoring blank nodes: Always filter blank nodes when counting or listing named entities.
- Assuming variable distinctness: SPARQL can bind
?xand?yto the same node. AddFILTER(?x != ?y)when distinct entities are required. - Ignoring entailment regime: A query that works on materialized endpoint results may fail on asserted-only local files.
Error Handling
| Error | Likely Cause | Recovery |
| Parse error | Syntax error in SPARQL | Run through validator; check missing PREFIXes or braces |
| Timeout | Query too complex or graph too large | Add LIMIT, rewrite with more selective patterns |
| Empty results | Wrong prefix IRI or term not in graph | Verify prefix resolves correctly; check term existence |
| 403 Forbidden | Endpoint requires authentication | Check credentials configuration |
| RDF-star syntax error | Store doesn't support RDF-star | Check store capabilities; fall back to standard reification |
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.

