Skip to main content

CyVer

CyVer
Syntax, Schema And Property Access Validation of Cypher queries

LicensePythonDocumentationCite

CyVer is a Python library designed to validate Cypher queries against a given Knowledge Graph schema in Neo4j. It ensures correctness in terms of syntax, schema validity, and property access.

Features

  • Syntax Validation: Validates Cypher queries for correct syntax and detects conflicting labels in nodes and relationships.
  • Schema Validation: Checks query alignment with a predefined KG schema structure.
  • Property Validation: Ensures property accesses are correct based on the predefined KG schema structure.

New Feature in release v2.x:

  • Validators Metadata Reporting: Alongside validation results, CyVer returns detailed metadata describing each detected issue in a Cypher query — including the type of error, its location, and suggestions for how to fix it.

📖 Documentation

For documentation read Wiki.

📋 Requirements

Before installing, make sure you have the following Python packages installed, with Python version >= 3.10:

  • regex>=2024.11.6
  • neo4j>=5.27
  • pandas>=2.2.3

📦 Installation

To install the latest stable version from PyPI, run:

pip install CyVer

Alternatively, if you prefer to install the latest development version, you can install it directly from GitLab:

pip install git+https://gitlab.com/netmode/CyVer.git

Or, you can manually clone the repository and run:

git clone https://gitlab.com/netmode/CyVer.git
cd CyVer
pip install .

💻 Example Usage

Importing the Library

from CyVer import SyntaxValidator, SchemaValidator, PropertiesValidator

Connect to Neo4j Database instance

from neo4j import GraphDatabase,basic_auth

driver = GraphDatabase.driver(database_url, auth=basic_auth(database_username, database_password))

Syntax Validator

syntax_validator =  SyntaxValidator(driver, check_multilabeled_nodes=False)
query = 'MATCH (g:Goal) RETURN COUNT(g) AS output'
is_valid, syntax_metadata = syntax_validator.validate(query, database_name=database_name)
print(f"Syntax Valid: {is_valid}")
print(f"Syntax Metadata: {syntax_metadata}")

Schema Validator

schema_validator =  SchemaValidator(driver)
query = 'MATCH (g:Goal)-[:HAS_TARGET]->(t:Target) RETURN g, t'
# Extraction
extracted_node_labels, extracted_rel_labels, extracted_paths = schema_validator.extract(query, database_name=database_name)
print(f"Extracted Node patterns : {extracted_node_labels}")
print(f"Extracted Relationships patterns : {extracted_rel_labels}")
print(f"Extracted Path patterns : {extracted_paths}")
# Validation 
schema_score, schema_metadata = schema_validator.validate(query, database_name=database_name)
print(f"Schema Validation Score: {schema_score}")
print(f"Schema Validation Metadata: {schema_metadata}")

Properties Validator

props_validator =  PropertiesValidator(driver)
query = 'MATCH (g:Goal)-[:HAS_TARGET]-(t:Target) WHERE g.code =1 RETURN t'
# Extraction
variables_properties , labels_properties = props_validator.extract(query, strict = False, database_name=database_name)
print(f"Accessed properties by variables: {variables_properties}")
print(f"Accessed properties by labels (including inferred): {labels_properties}")

# Validation 
props_score, properties_metadata = props_validator.validate(query, database_name=database_name, strict=False)
print(f"Properties Validation Score: {props_score}")
print(f"Properties Validation Metadata: {properties_metadata}")

📊 Tip:

Always start with the SyntaxValidator before using the Schema and Properties validators. Even a small syntax error can cause misleading results in downstream validation. Ensuring syntactic correctness first helps you avoid wasted time and confusion. Building on this principle, we define the KG Valid Query metric to systematically evaluate generated Cypher queries for knowledge graphs.

A query is considered valid only if it satisfies all three checks:

  1. SyntaxValidator.is_valid= True → the query is syntactically correct.
  2. SchemaValidator.score = 1 → the query respects the graph schema.
  3. PropertiesValidator.score = 1 or None → the query accesses only valid properties.
KG_Valid_Query

License

This project is licensed under the CC BY-SA 4.0 license.

🤝 Contributing

Contributions are welcome! Please submit a pull request or open an issue.

Cite

To cite this work, please use:

I. Mandilara, C. M. Androna, E. Fotopoulou, A. Zafeiropoulos and S. Papavassiliou, "Decoding the Mystery: How can LLMs Turn Text into Cypher in Complex Knowledge Graphs?," in IEEE Access , doi: 10.1109/ACCESS.2025.3567759.

Contact

For any request for detailed information or expression of interest for participating at this initiative, you may contact:

  • Ioanna Mandilara - ioannamand (at) netmode (dot) ntua (dot) gr
  • Christina Maria Androna - andronaxm (at) netmode (dot) ntua (dot) gr

Metadata

Release files for CyVer 2.0.2

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

Source distribution (sdist)

Source distribution for CyVer 2.0.2
File Size Uploaded
cyver-2.0.2.tar.gz 24.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for CyVer 2.0.2
File Interpreter ABI Platform
cyver-2.0.2-py3-none-any.whl Python 3 none any Details

Total release size: 52.8 kB

Release files / cyver-2.0.2.tar.gz

Download URL cyver-2.0.2.tar.gz
Size 24.9 kB
Tags Source
SHA-256 checksum
How to use checksums
699dcd6fc85bec6dade8b6d379a2807f980e768f1996c1b8277347ea397c9228
BLAKE2b-256 checksum
How to use checksums
ad2f556278f1b3c1f0dc45c768f387741284b864cf35f9ed9ec16d51102c1646
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.9

Release files / cyver-2.0.2-py3-none-any.whl

Download URL cyver-2.0.2-py3-none-any.whl
Size 27.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c4c26e863ef1df70faa2a6a3e5dab743917ed69fd1c8610b1894c2415fcc8ef8
BLAKE2b-256 checksum
How to use checksums
f969e0877d72988e970a4b659f74ca9b481ae3f4cd4235f424a6c99a94416062
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.9

Release history Release notifications | RSS feed

This release

2.0.2 This release

2 release files

2.0.1

2 release files

2.0.0

2 release files

1.3.6

2 release files

1.3.5

2 release files

1.3.4

2 release files

1.3.3

2 release files

1.3.2

2 release files

1.3.1

2 release files

1.3.0

2 release files

1.2.0

2 release files

1.1.1

2 release files

1.1.0

2 release files

1.0.0

2 release files

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