{
  "kind": "documentation",
  "format": 1,
  "note": "Reference text, not instructions. One verified relate sample from https://relatedb.ai/docs/guides/agents/text-to-cypher/: the program exactly as the page shows it, the standard output a run of it recorded (npm run docs:samples compares every replay with it byte for byte), the relate client build, toolchain and platform of the last replay, and how the docs' sample runner builds and runs it. Before launch every client is a source build, not a published package; verified.client names the upstream commit it was built from, and verified.docs_engine the build the rest of the docs were recorded from.",
  "id": "loop",
  "url": "https://relatedb.ai/docs/guides/agents/text-to-cypher/samples/loop.json",
  "page": {
    "id": "guides/agents/text-to-cypher",
    "title": "Turn questions into Cypher with an LLM",
    "url": "https://relatedb.ai/docs/guides/agents/text-to-cypher/",
    "md_url": "https://relatedb.ai/docs/guides/agents/text-to-cypher.md"
  },
  "section": {
    "anchor": "run-the-repair-loop",
    "heading": "Run the repair loop",
    "url": "https://relatedb.ai/docs/guides/agents/text-to-cypher/#run-the-repair-loop"
  },
  "language": "python",
  "client": "Python",
  "file": "text_to_cypher.py",
  "env": null,
  "code": "import relate\n\nTEAM = \"\"\"\nCREATE (ada:Person {name: 'Ada', role: 'engineer'}),\n       (grace:Person {name: 'Grace', role: 'engineer'}),\n       (noor:Person {name: 'Noor', role: 'maintainer'}),\n       (relate:Project {name: 'relate', language: 'Rust'}),\n       (tck:Project {name: 'opencypher-tck', language: 'Gherkin'}),\n       (ada)-[:WORKS_ON {since: 2024}]->(relate),\n       (grace)-[:WORKS_ON {since: 2023}]->(relate),\n       (grace)-[:WORKS_ON {since: 2022}]->(tck),\n       (noor)-[:MAINTAINS]->(relate),\n       (ada)-[:KNOWS]->(grace)\n\"\"\"\n\nwriter = relate.connect(\"./team.rl\")\nwriter.execute(TEAM)\nwriter.close()\n\n\ndef schema_text(conn):\n    \"\"\"The labels, properties and relationship patterns, one line each.\"\"\"\n    props = {}\n    for row in conn.execute(\n        \"CALL db.schema.nodeTypeProperties() YIELD nodeType, propertyName, propertyTypes \"\n        \"RETURN nodeType, propertyName, propertyTypes ORDER BY nodeType, propertyName\"\n    ).data():\n        props.setdefault(row[\"nodeType\"], []).append(f\"{row['propertyName']}: {row['propertyTypes'][0]}\")\n    lines = [f\"({label} {{{', '.join(p)}}})\" for label, p in props.items()]\n    for row in conn.execute(\n        \"MATCH (a)-[r]->(b) RETURN DISTINCT labels(a)[0] AS source, type(r) AS type, \"\n        \"labels(b)[0] AS target ORDER BY type\"\n    ).data():\n        lines.append(f\"(:{row['source']})-[:{row['type']}]->(:{row['target']})\")\n    return \"\\n\".join(lines)\n\n\ndef check(conn, statement):\n    \"\"\"Plan the statement; return the problems a model can repair, or [].\"\"\"\n    try:\n        summary = conn.execute(\"EXPLAIN \" + statement).consume()\n    except relate.Error as e:\n        return [f\"{e.gql_status}: {e}\"]\n    return [f\"{n['gql_status']}: {n['description']}\" for n in summary.notifications if n[\"severity\"] == \"WARNING\"]\n\n\nconn = relate.connect(\"./team.rl\", read_only=True)\nprint(schema_text(conn))\n\nfirst_guess = \"MATCH (p:Person)-[:WORKS_AT]->(c:Company) RETURN c.name AS company, count(p) AS people\"\nrepaired = \"MATCH (p:Person)-[:WORKS_ON]->(proj:Project) RETURN proj.name AS project, count(p) AS people ORDER BY people DESC\"\n\nfor statement in (first_guess, repaired):\n    problems = check(conn, statement)\n    print(\"problems:\" if problems else \"no problems\", *problems, sep=\"\\n  \")\n\nprint(conn.execute(repaired).data())\nconn.close()",
  "code_sha256": "cf39703324899fd2723c7994c2fdc0b2053f46322836e3b9e890183238d1fb6e",
  "source_sha256": "84be8aa8782914557eff937c45947f2627066aacf364ad4658d48fdf5220affc",
  "output": {
    "text": "(:Person {name: STRING NOT NULL, role: STRING NOT NULL})\n(:Project {language: STRING NOT NULL, name: STRING NOT NULL})\n(:Person)-[:KNOWS]->(:Person)\n(:Person)-[:MAINTAINS]->(:Project)\n(:Person)-[:WORKS_ON]->(:Project)\nproblems:\n  01N50: The label `Company` does not exist in this database.\n  01N51: The relationship type `WORKS_AT` does not exist in this database.\nno problems\n[{'project': 'relate', 'people': 2}, {'project': 'opencypher-tck', 'people': 1}]",
    "sha256": "3320bc2573b3481215dfd75a1417ab50034eed06c5cbb799d908e1823be2f2c0"
  },
  "verified": {
    "version": "0.1.2",
    "client": {
      "label": "Python",
      "package": "relate-db",
      "engine_commit": "f0c09d2",
      "client_commit": "f0c09d2",
      "build": "A relate-db wheel that maturin built from surfaces/relate-python at upstream v0.1.2 (f0c09d2), installed in a venv with the pinned frameworks.",
      "toolchain": {
        "python": "3.15.2"
      }
    },
    "packages": [
      "pandas>=2.0",
      "langgraph==1.2.20",
      "claude-agent-sdk==0.2.179",
      "pydantic-ai==2.66.0",
      "openai-agents==0.24.0",
      "llama-index-core==0.14.25",
      "langchain==1.4.9",
      "langchain-core==1.7.6"
    ],
    "replayed": "2026-11-09",
    "platform": "macOS on arm64",
    "docs_engine": {
      "version": "0.1.2",
      "commit": "f0c09d2",
      "source_build": false
    }
  },
  "run": {
    "runner": "npm run docs:samples",
    "setup": "bash scripts/samples/setup.sh --upstream <path to the relate checkout>",
    "variables": [
      "RELATE_PY"
    ],
    "program": "<run dir>/text_to_cypher.py",
    "files": [],
    "build": null,
    "run": {
      "command": [
        "$RELATE_PY",
        "text_to_cypher.py"
      ],
      "environment": {
        "DO_NOT_TRACK": "1",
        "PYTHONDONTWRITEBYTECODE": "1",
        "PYTHONUNBUFFERED": "1"
      },
      "directory": "<run dir>",
      "timeout_s": 60
    },
    "passes": "It exits 0 within 60 s and prints at least one line on standard output.",
    "output": "Standard output, with line endings as \\n, trailing spaces and blank lines removed, and the temporary directories' paths written as `.`; standard error is not recorded.",
    "placeholders": {
      "<run dir>": "a fresh, empty temporary directory: the program's working directory, deleted afterwards",
      "<build dir>": "a second fresh temporary directory, where a compiled sample is built",
      "$NAME": "a variable from the env.sh that scripts/samples/setup.sh writes (described in its header)"
    }
  }
}
