liveBook · Manning

Automated query generation

As explained in Knowledge Graphs and LLMs in Action

Query generation is the process of producing an executable database query from a natural-language request, structured intent, or other specifications.

Automated query generation converts a natural-language question into an executable database query. In a knowledge-graph system, it combines structured user intent, an LLM-friendly schema, prompt constraints, and execution feedback to formulate and refine Cypher. section 14.7 section 15.1.5

A reliability-focused pipeline typically proceeds through these stages:

  • Prepare the question, annotated graph schema, intent-dependent requirements, examples, optional selection state, and an explicit output format. section 14.7.2
  • Ask the model to identify relationships it may traverse and explain its reasoning before producing the final Cypher query. section 14.7.3
  • Execute the generated query, capture database errors, and retry the text-to-Cypher stage when execution fails. section 15.1.5
  • Route successful results either directly to completion or through summarization according to the requested output type. section 15.1.5

Crime investigation query

For the request “Return one crime node currently under investigation,” the system detects the graph-oriented response, generates Cypher with the active-investigation constraint, displays a crime node, and explains its interpretation and execution. section 15.3.1

Figure 14.11 The complete flow of transforming a natural language question into a Cypher query, showing how three inputs are processed through structured prompt components. The process is organized into three stages (Input processing, Context building, and Final guidelines) that culminate in structured JSON output.
figure

The pipeline diagram shows how question, schema, and contextual requirements move through input processing, context building, and final guidelines into structured query output. section 14.7.2

How Knowledge Graphs and LLMs in Action covers it

How deep it goes
Explains prompt structure, staged output, execution feedback, retries, and routing, but does not detail Cypher parsing internals.
Examples
Uses annotated schema prompts, structured JSON responses, execution retries, and a crime-investigation request as concrete artifacts.
What it assumes
Assumes a knowledge-graph schema, intent-detection output, and Neo4j access; supplies schema formatting and prompt construction for the model.
What you can do after
Build a grounded text-to-Cypher pipeline that validates execution, retries failures, and exposes query reasoning.
How it connects
Connects intent detection, schema extraction, prompt engineering, Cypher, Neo4j, query execution, summarization, and LangGraph.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Knowledge Graphs and LLMs in Action. The section links point to the parts of the book it draws on.