The natural-language-to-Cypher prompt

The chain ships with a default prompt that embeds your graph schema and asks the LLM to generate Cypher. When the LLM produces wrong queries, the prompt is the first place to look. The schema string you pass in matters more than any prompt tweak; a complete schema makes the LLM write correct Cypher, an incomplete one makes it hallucinate labels.

graph_store.py
python
def schema_string(self):
    """Text description of the graph schema for LLM prompts."""
    try:
        return self.connect().schema
    except Exception:
        return ""

Neo4jGraph.schema exposes a generated text description of every label, relationship type, and property key in the database. The chain feeds this string into the Cypher-generation prompt. If your graph has new labels you just ingested, call refresh_schema() before asking questions so the prompt stays accurate.

AI prompt: Try it: Cypher generation prompt

Loading practice…

Quiz: Quiz

Loading practice…

Checkpoint: Cypher answers checkpoint

Loading practice…