Analyze 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)When analyzing a query, the tool performs these validation steps:
Broken Cypher query:
text
MATCH (p:Person)-[:WORKS_AT]->(c:Company
RETURN p
Issue: Missing closing parenthesis for Company node.
Fixed query:
text
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:
text
SELECT ?person
WHERE {
?person rdf:type :Person
?person :worksAt :Acme .
}
Issue: Missing period between triple statements.
Fixed query:
text
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:
text
MATCH (p:Person)
WHERE p.age > "30"
RETURN p
Issue: Comparing numeric property with string literal.
Fixed query:
text
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:
text
MATCH (p:Employee)-[:WORKS_AT]->(c:Company)
RETURN p
Problem: The label Employee may not exist in the graph schema.
Possible correction:
text
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:
text
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:
text
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:
text
MATCH (p:Person)
WHERE p.age > 30
RETURN p.age, p.salary
Problem: The property salary may not exist on Person nodes.
Debugging approach:
text
MATCH (p:Person)
RETURN keys(p)
LIMIT 5
Explanation: Use the keys() function to inspect actual properties on nodes before writing complex queries.
Query:
text
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:
text
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:
text
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:
text
-- 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:
text
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:
text
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:
text
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
text
MATCH (p:Person {name:"Alice"})
RETURN p
Step 2: Check if Google exists
text
MATCH (c:Company {name:"Google"})
RETURN c
Step 3: Check Alice's relationships
text
MATCH (p:Person {name:"Alice"})-[r]->(target)
RETURN r, target
Step 4: Relax constraints progressively
text
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:
text
SELECT ?person
WHERE {
?person rdf:type Person
}
Issue: Person is referenced without a namespace prefix.
Fixed query:
text
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:
text
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:
text
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:
text
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:
text
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:
text
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:
text
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:
text
MATCH (p:Person), (c:Company)
RETURN p, c
Problem: Without relationship constraints, this creates a Cartesian product of all persons and companies.
Corrected query:
text
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:
text
MATCH (p:Person {email: "alice@example.com"})
RETURN p
Suggestion: Create an index on Person.email
text
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:
json
{
"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.