Back openDesk Edu for a sovereign, open-source education β every vote counts.
Vote nowText-to-Cypher is the feature every graph product wants and every query engineer quietly fears. The LLM is excellent at producing Cypher that reads like the answer. It is equally good at producing a query that is wrong, catastrophically slow, or β in the worst case β a full-graph scan disguised as a question. The fix is not to abandon text-to-Cypher. It is to treat every generated query as untrusted input and move it behind the same discipline you apply to user-facing code: validation, ceilings, and tests in CI.
MATCH scans the whole
graph, a missing index turns a lookup into a traversal.MERGE, SET,
or deletion clauses and mutates data.Each needs a different guard.
The cheapest guard is structural: validate the generated Cypher against the schema before the database ever sees it.
MATCH, RETURN,
WHERE, WITH, ORDER BY, limits); explicitly reject MERGE,
SET, DETACH DELETE, and CALL unless the feature truly needs write.:Label and property references a real one. A typo label is
the classic "correct-looking, wrong" failure β catch it before the query.MATCH (n:Label) with no starting
bound value and no path from a bound node is a scan; block it by default.Result: a hard, fast, pre-execution filter that removes wrongness and the worst of the expense, with no query executed.
Schema validation stops wrong and structurally-bad queries. Cost ceilings catch the correct-but-expensive ones that slip through (index path choices, fan-out). Set explicit limits and enforce them:
LIMIT enforced at the app layer, plus a max-returned-rows cap).The only thing that catches semantic wrongness reliably is running the queries against known data. Build a small, fast, isolated fixture graph that parodies your real schema, and test generated queries in CI:
Now text-to-Cypher has the same safety net as application code: a wrong or expensive query is caught by CI before it ships, instead of on production data.
The mental model that makes it work: a generated query is user input with extra steps. You would never pass raw user input straight to your graph driver; you validate, bind, and limit. Treat LLM output identically β it is just input you didn't type. Schema validation for what it may touch, ceilings for how much it may do, CI fixture tests for whether it's actually right.
Text-to-Cypher doesn't need to be trusted to be useful. It needs to be guarded. With validation, budgets, and a test harness, you publish the feature confidently β because every generated query has already proven it can't be wrong, can't blow up the graph, and can't do it silently twice.