Install
openclaw skills install graph-query-debugging-toolDiagnose errors in Cypher or SPARQL queries and suggest fixes for syntax issues, schema mismatches, and incorrect graph traversal patterns.
openclaw skills install graph-query-debugging-toolAnalyze graph queries, identify errors, and suggest fixes.
This skill helps developers debug graph database queries by detecting syntax errors, schema mismatches, incorrect relationship patterns, and logical mistakes.
It explains why a query fails or returns incorrect results and provides corrected query versions.
Use this skill when a user wants to:
The debugging tool provides:
Cypher Query Components:
(n:Label {prop: value})-[r:TYPE]->, <-[r:TYPE]-SPARQL Query Components:
?s ?p ?oPREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>?variableFILTER (?var > 5)Syntax Errors - Malformed query structure
Schema Errors - References to non-existent elements
Relationship Errors - Issues with relationship traversal
Logical Errors - Query logic problems
Performance Issues - Queries that are inefficient
When analyzing a query, the tool performs these validation steps:
Broken Cypher query:
MATCH (p:Person)-[:WORKS_AT]->(c:Company
RETURN p
Issue: Missing closing parenthesis for Company node.
Fixed query:
MATCH (p:Person)-[:WORKS_AT]->(c:Company)
RETURN p
Explanation: All node patterns must be properly enclosed in parentheses. The query declares a Company node pattern but fails to close it before the RETURN clause.
Broken SPARQL query:
SELECT ?person
WHERE {
?person rdf:type :Person
?person :worksAt :Acme .
}
Issue: Missing period between triple statements.
Fixed query:
SELECT ?person
WHERE {
?person rdf:type :Person .
?person :worksAt :Acme .
}
Explanation: Each RDF triple in SPARQL must end with a period. The first triple is missing its terminating period, causing a syntax error.
Broken Cypher query:
MATCH (p:Person)
WHERE p.age > "30"
RETURN p
Issue: Comparing numeric property with string literal.
Fixed query:
MATCH (p:Person)
WHERE p.age > 30
RETURN p
Explanation: The age property is numeric, so it should be compared with a numeric value, not a string. Type mismatches cause unexpected behavior.
Query:
MATCH (p:Employee)-[:WORKS_AT]->(c:Company)
RETURN p
Problem: The label Employee may not exist in the graph schema.
Possible correction:
MATCH (p:Person)-[:WORKS_AT]->(c:Company)
RETURN p
Explanation: Different graph schemas use different naming conventions. Common alternatives: Person, Actor, User, Individual. The debugging tool suggests schema-aligned labels.
Query:
MATCH (p:Person)-[:WORK_AT]->(c:Company)
RETURN p
Issue: Relationship type WORK_AT (singular) may be incorrect; WORKS_AT (plural) is more likely.
Corrected query:
MATCH (p:Person)-[:WORKS_AT]->(c:Company)
RETURN p
Explanation: Common naming pattern mismatches. The tool checks against known relationship patterns and suggests corrections based on schema definitions.
Query:
MATCH (p:Person)
WHERE p.age > 30
RETURN p.age, p.salary
Problem: The property salary may not exist on Person nodes.
Debugging approach:
MATCH (p:Person)
RETURN keys(p)
LIMIT 5
Explanation: Use the keys() function to inspect actual properties on nodes before writing complex queries.
Query:
MATCH (c:Company)<-[:WORKS_AT]-(p:Person)
RETURN p
Possible issue: The relationship direction may be reversed. Should be Person -[:WORKS_AT]-> Company.
Corrected query:
MATCH (p:Person)-[:WORKS_AT]->(c:Company)
RETURN p
Explanation: Relationship direction matters. If the schema defines WORKS_AT as Person -> Company, the reverse direction produces no results.
Query:
MATCH (a:Person)-[:KNOWS]->(b:Person)-[:WORKS_AT]->(c:Company)
RETURN a, b, c
Problem: Relationship chain may be incomplete or require intermediate nodes.
Debugging approach:
-- First, check the KNOWS relationship
MATCH (a:Person)-[:KNOWS]->(b:Person)
RETURN a, b
LIMIT 10
-- Then, check if Person nodes connect to Company
MATCH (b:Person)-[:WORKS_AT]->(c:Company)
RETURN b, c
LIMIT 10
Explanation: Break complex queries into intermediate steps to isolate where the chain breaks.
Query:
MATCH (p:Person)-[:LIKES]->(p2:Person)-[:MANUFACTURES]->(prod:Product)
RETURN p, prod
Problem: Person nodes may not have MANUFACTURES relationships; that relationship may only exist from Company to Product.
Corrected query:
MATCH (p:Person)-[:WORKS_AT]->(c:Company)-[:MANUFACTURES]->(prod:Product)
RETURN p, prod
Explanation: Relationships often connect specific node types. The tool validates that relationship types connect compatible node labels.
Example query:
MATCH (p:Person {name:"Alice"})-[:WORKS_AT]->(c:Company {name:"Google"})
RETURN p
Possible issues:
EMPLOYED_BY instead of WORKS_AT)Step 1: Check if Alice exists
MATCH (p:Person {name:"Alice"})
RETURN p
Step 2: Check if Google exists
MATCH (c:Company {name:"Google"})
RETURN c
Step 3: Check Alice's relationships
MATCH (p:Person {name:"Alice"})-[r]->(target)
RETURN r, target
Step 4: Relax constraints progressively
MATCH (p:Person {name:"Alice"})-[:WORKS_AT]->(c:Company)
RETURN p, c
This reveals the actual relationships and targets connected to Alice, helping isolate the mismatch.
Broken SPARQL query:
SELECT ?person
WHERE {
?person rdf:type Person
}
Issue: Person is referenced without a namespace prefix.
Fixed query:
PREFIX ex: <http://example.org/>
SELECT ?person
WHERE {
?person rdf:type ex:Person
}
Explanation: RDF requires full URIs. Prefixes abbreviate long namespace URIs. Without a prefix, the term is interpreted as a bare string, not a resource URI.
Broken SPARQL query:
SELECT ?person
WHERE {
?person rdf:type ex:Person .
?person ex:age ?age .
FILTER (?age > "30")
}
Issue: Type mismatch in filter; comparing numeric age with string "30".
Fixed query:
PREFIX ex: <http://example.org/>
SELECT ?person
WHERE {
?person rdf:type ex:Person .
?person ex:age ?age .
FILTER (?age > 30)
}
Explanation: SPARQL FILTER expressions require type-compatible comparisons. Numeric properties must be compared with numeric literals.
Query with potential issue:
SELECT ?person ?email
WHERE {
?person rdf:type ex:Person .
?person ex:email ?email .
}
Problem: If not all Person nodes have email, query returns incomplete results.
Optimized query:
PREFIX ex: <http://example.org/>
SELECT ?person ?email
WHERE {
?person rdf:type ex:Person .
OPTIONAL { ?person ex:email ?email }
}
Explanation: Use OPTIONAL to include results even when optional properties are missing.
Inefficient query:
MATCH (p:Person)-[:WORKS_AT]->(c:Company)
WHERE p.age > 30
RETURN p
Problem: Filters are applied after relationship matching, processing all relationships first.
Optimized query:
MATCH (p:Person)
WHERE p.age > 30
MATCH (p)-[:WORKS_AT]->(c:Company)
RETURN p
Explanation: Apply filters early to reduce the working set before expensive relationship traversals.
Problematic query:
MATCH (p:Person), (c:Company)
RETURN p, c
Problem: Without relationship constraints, this creates a Cartesian product of all persons and companies.
Corrected query:
MATCH (p:Person)-[:WORKS_AT]->(c:Company)
RETURN p, c
Explanation: Always specify relationship patterns to limit the result set to relevant combinations.
Query that benefits from indexing:
MATCH (p:Person {email: "alice@example.com"})
RETURN p
Suggestion: Create an index on Person.email
CREATE INDEX ON :Person(email)
Explanation: Indexes accelerate exact-match lookups. If frequently querying by specific properties, create indexes.
The debugging tool provides multiple output formats:
Human-readable breakdown of all issues:
{
"query": "...",
"query_type": "cypher",
"has_errors": true,
"error_count": 2,
"errors": [
{
"category": "syntax",
"line": 1,
"message": "Missing closing parenthesis",
"position": 45,
"suggestion": "Add ) after Company"
},
{
"category": "schema",
"message": "Relationship type WORK_AT not found",
"suggestion": "Did you mean WORKS_AT?"
}
]
}
The debugged and corrected version of the query ready for execution.
Step-by-step guidance for manual debugging and investigation.
Details on schema element validation results.
The debugging tool internally performs:
Python:
lark - Query parsing and tokenizationregex - Pattern matching for query analysisdataclasses-json - Serialization of analysis resultsjsonschema - Schema validation for provided schemasJavaScript/Node.js:
cypher-parser - Cypher query parsingsparql-parser - SPARQL query parsingjson-schema-validator - Schema validationWhen debugging graph queries:
This skill integrates with:
This skill helps developers diagnose and fix issues in graph queries across multiple query languages.
It detects syntax errors, schema mismatches, relationship traversal issues, and logical mistakes while providing corrected query versions and step-by-step debugging guidance. Whether working with Cypher, SPARQL, or other graph query languages, the debugging tool accelerates query development and troubleshooting.
Status: Enterprise-Grade Query Debugging Tool
Comprehensive error detection, schema validation, and query assistance for professional knowledge graph development.