Skip to main content

neo4j-guard

A guardrail for LLM-generated Cypher, built for Neo4j.

By default, only read queries are allowed. Writes, LOAD CSV and APOC procedures are blocked unless explicitly allowed.

Requirements

  • Python 3.10+
  • neo4j 5.8+

Installation

pip install neo4j-guard

Usage

Pass an existing driver to guard() and give the guarded driver to the agent:

from neo4j_guard import GuardError, guard

db = guard(driver, mode="read")

try:
    result = db.execute_query("MATCH (p:Person) DETACH DELETE p")
except GuardError as error:
    print(error)  # DELETE is not allowed in read mode

With LangChain, guard the driver of Neo4jGraph:

from langchain_neo4j import Neo4jGraph

graph = Neo4jGraph(url, username, password)
guard(graph._driver)

With the Neo4j MCP server, guard the driver passed to create_mcp_server():

from mcp_neo4j_cypher.server import create_mcp_server
from neo4j import AsyncGraphDatabase

mcp = create_mcp_server(guard(AsyncGraphDatabase.driver(url, auth=auth), allow=["apoc.meta.*"]))

Configuration

Modes

mode sets the defaults. "read" (or "readonly") is the default mode, and "write" (or "readwrite") also allows creating and updating data.

db = guard(driver, mode="write")
Read Write
Read clauses (MATCH, RETURN, WITH, ...) ✓ ✓
Write clauses (CREATE, MERGE, SET, ...) ✓
Delete clauses (DELETE, DETACH DELETE)
Other clauses (LOAD CSV, USE)
Built-in functions (toUpper, count, ...) ✓ ✓
Schema and search procedures (db.labels, db.index.vector.queryNodes, ...) ✓ ✓
Other procedures and functions (apoc.*, dbms.*, ...)
Admin commands (SHOW USERS, CREATE INDEX, ...)

Allow and disallow

allow and disallow adjust the defaults.

db = guard(driver, allow=["apoc.meta.*"], disallow=["Employee", "Person.ssn"])
Example allow disallow
Clause "DELETE" ✓ ✓
Procedure or function "apoc.load.json", "apoc.meta.*" ✓ ✓
Label or relationship type "Employee" ✓
Property "Person.ssn" ✓

Labels and properties are checked in the query and in returned nodes, relationships and paths. A query can still reach them without naming them, for example through labels(n), so this does not replace Neo4j's access control.

Metadata

Release files for neo4j-guard 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for neo4j-guard 0.1.0
File Size Uploaded Provenance Actions
neo4j_guard-0.1.0.tar.gz 178.9 kB With provenance Details for neo4j_guard-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for neo4j-guard 0.1.0
File Interpreter ABI Platform Actions
neo4j_guard-0.1.0-py3-none-any.whl Python 3 none any Details for neo4j_guard-0.1.0-py3-none-any.whl

Total release size: 366.8 kB

Release files / neo4j_guard-0.1.0.tar.gz

Download URL neo4j_guard-0.1.0.tar.gz
Size 178.9 kB
Tags Source
SHA-256 checksum
How to use checksums
8221a4ad84b52fbf5694a22d8461aec0c3d8c6e6f498b1cdd7880a02b3dff1e8
BLAKE2b-256 checksum
How to use checksums
8b59623c18d4f76b80e291a8a5339043f82b5d0a82f0fc71827d053e2f3e8960
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 11, 2026.

Transparency log

Release files / neo4j_guard-0.1.0-py3-none-any.whl

Download URL neo4j_guard-0.1.0-py3-none-any.whl
Size 188.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d8059d31ace70f6dadcbbba7f735107bd0006c21ff519c978aff1cd007f6e871
BLAKE2b-256 checksum
How to use checksums
46e224f594ead27503332a4d9299a81cc13e46264b8ce07228a4c8a34684d1e9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 11, 2026.

Transparency log

Security for neo4j-guard 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for neo4j_guard-0.1.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 11, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page