Files
genai-toolbox/docs/en/resources/tools/neo4j/neo4j-execute-cypher.md
nester-neo4j f475da63ce feat(neo4j): Add dry_run parameter to validate Cypher queries (#1769)
This pull request adds support for a new `dry_run` mode to the Neo4j
Cypher execution tool, allowing users to validate queries and view
execution plans without running them. It also sets a custom user agent
for Neo4j connections and improves error handling and documentation. The
most important changes are grouped below.

### New dry run feature for Cypher execution

* Added an optional `dry_run` boolean parameter to the
`neo4j-execute-cypher` tool, allowing users to validate Cypher queries
and receive execution plan details without running the query. The tool
now prepends `EXPLAIN` to the query when `dry_run` is true and returns a
structured summary of the execution plan.
[[1]](diffhunk://#diff-de7fdd7e68c95ea9813c704a89fffb8fd6de34e81b43a484623fdff7683e18f3L87-R93)
[[2]](diffhunk://#diff-de7fdd7e68c95ea9813c704a89fffb8fd6de34e81b43a484623fdff7683e18f3R155-R188)
[[3]](diffhunk://#diff-de7fdd7e68c95ea9813c704a89fffb8fd6de34e81b43a484623fdff7683e18f3R219-R236)
[[4]](diffhunk://#diff-1dca93fc9450e9b9ea64bc1ae02774c3198ea6f8310b2437815bd1a5eae11e79L30-R32)
* Updated integration tests to cover the new `dry_run` functionality,
including successful dry runs, error handling for invalid syntax, and
enforcement of read-only mode.
[[1]](diffhunk://#diff-b07de4a304bc72964b5de9481cbc6aec6cf9bb9dabd903a837eb8974e7100a90R163-R169)
[[2]](diffhunk://#diff-b07de4a304bc72964b5de9481cbc6aec6cf9bb9dabd903a837eb8974e7100a90R250-R291)

### Improved error handling

* Enhanced error messages for parameter casting in the tool's `Invoke`
method to clarify issues with input parameters.

### Neo4j driver configuration

* Set a custom user agent (`genai-toolbox/neo4j-source`) for Neo4j
driver connections to help identify requests from this tool.
[[1]](diffhunk://#diff-3f0444add0913f1722d678118ffedc70039cca3603f31c9927c06be5e00ffb29R24-R29)
[[2]](diffhunk://#diff-3f0444add0913f1722d678118ffedc70039cca3603f31c9927c06be5e00ffb29L109-R113)

### Documentation updates

* Updated the documentation to describe the new `dry_run` parameter and
its usage for query validation.

---------

Co-authored-by: Yuan Teoh <45984206+Yuan325@users.noreply.github.com>
2025-10-23 15:22:13 -07:00

2.8 KiB

title, type, weight, description, aliases
title type weight description aliases
neo4j-execute-cypher docs 1 A "neo4j-execute-cypher" tool executes any arbitrary Cypher statement against a Neo4j database.
/resources/tools/neo4j-execute-cypher

About

A neo4j-execute-cypher tool executes an arbitrary Cypher query provided as a string parameter against a Neo4j database. It's designed to be a flexible tool for interacting with the database when a pre-defined query is not sufficient. This tool is compatible with any of the following sources:

For security, the tool can be configured to be read-only. If the readOnly flag is set to true, the tool will analyze the incoming Cypher query and reject any write operations (like CREATE, MERGE, DELETE, etc.) before execution.

The Cypher query uses standard Neo4j Cypher syntax and supports all Cypher features, including pattern matching, filtering, and aggregation.

neo4j-execute-cypher takes a required input parameter cypher and run the cypher query against the source. It also supports an optional dry_run parameter to validate a query without executing it.

Note: This tool is intended for developer assistant workflows with human-in-the-loop and shouldn't be used for production agents.

Example

tools:
  query_neo4j:
    kind: neo4j-execute-cypher
    source: my-neo4j-prod-db
    readOnly: true
    description: |
      Use this tool to execute a Cypher query against the production database.
      Only read-only queries are allowed.
      Takes a single 'cypher' parameter containing the full query string.
      Example:
      {{
          "cypher": "MATCH (m:Movie {title: 'The Matrix'}) RETURN m.released"
      }}

Reference

field type required description
kind string true Must be "neo4j-cypher".
source string true Name of the source the Cypher query should execute on.
description string true Description of the tool that is passed to the LLM.
readOnly boolean false If set to true, the tool will reject any write operations in the Cypher query. Default is false.