Skip to main content

Turn natural language into read-only Cypher, validate it with CyVer, and execute it against Neo4j — powered by LiteLLM.

Project description

cyphersmith

cyphersmith turns natural language into read-only Cypher, validates it with CyVer, executes it against Neo4j, and returns the query plus records.

It uses LiteLLM for provider-neutral model access, so the same package works with OpenAI, Azure OpenAI, Anthropic, Gemini, and all other LiteLLM-supported providers.

Install

pip install cyphersmith

Python API

from cyphersmith import CypherGenerator, LLMConfig, Neo4jCredentials

generator = CypherGenerator(
    neo4j=Neo4jCredentials(
        uri="bolt://localhost:7687",
        username="neo4j",
        password="password",
        database="neo4j",
    ),
    llm=LLMConfig(
        model="openai/gpt-4o-mini",
        temperature=0,
    ),
    business_context_path="business_context.yaml",
)

result = generator.ask("show top 10 items by a chosen metric")
print(result.cypher)
print(result.records)

CLI

Interactive setup and question loop:

cyphersmith chat --pretty

The interactive command prompts for:

  • LLM provider and model
  • API key and any provider-specific endpoint values
  • Neo4j URI, username, password, and database
  • optional business context file path

After setup, keep asking questions at Question>. Type /exit to stop. Each answer prints the generated Cypher query, records, validation details, attempts, and any error.

One-shot command:

cyphersmith ask \
  --neo4j-uri bolt://localhost:7687 \
  --neo4j-user neo4j \
  --neo4j-password password \
  --neo4j-database neo4j \
  --model openai/gpt-4o-mini \
  --business-context business_context.yaml \
  "show top 10 items by a chosen metric"

The CLI prints live intermediate progress steps to stderr (context load, schema fetch, generation attempts, safety checks, validation, and execution) with terminal colors for readability. Final structured output stays on stdout.

Use these flags if needed:

  • --no-progress: disable intermediate step logs
  • --no-color: keep progress logs but disable ANSI colors

The final CLI payload includes cypher, records, validation, attempts, and error.

Environment Variables

Neo4j values can be passed explicitly or read from:

  • NEO4J_URI
  • NEO4J_USER
  • NEO4J_PASSWORD
  • NEO4J_DATABASE

LiteLLM credentials should use the environment variables expected by the provider, such as OPENAI_API_KEY, AZURE_API_KEY, AZURE_API_BASE, or provider-specific equivalents.

Business Context

Pass a .txt, .md, .yaml, .yml, or .json file through business_context_path or --business-context. The content is added to the Cypher generation prompt as business context only; it is not treated as a schema source.

Safety

Generated Cypher is blocked unless it passes both:

  • a local read-only keyword/procedure check
  • CyVer syntax, schema, and property validation

The package will not execute generated queries containing obvious write operations such as CREATE, MERGE, DELETE, SET, REMOVE, or procedures like CALL db and CALL apoc.

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cyphersmith-0.1.0.tar.gz (23.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cyphersmith-0.1.0-py3-none-any.whl (22.4 kB view details)

Uploaded Python 3

File details

Details for the file cyphersmith-0.1.0.tar.gz.

File metadata

  • Download URL: cyphersmith-0.1.0.tar.gz
  • Upload date:
  • Size: 23.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.8

File hashes

Hashes for cyphersmith-0.1.0.tar.gz
Algorithm Hash digest
SHA256 4a6daa577809d511ee32e26e1bd51552ec5eb89baf84a5912f1e78d333db2637
MD5 9ebb1eaac81c82e47da4627ec3db080e
BLAKE2b-256 92b4564964e362b0f1103fd20a84ddf65197900bd36ea168dc70ae63b239eb4b

See more details on using hashes here.

File details

Details for the file cyphersmith-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: cyphersmith-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 22.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.8

File hashes

Hashes for cyphersmith-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 91b581d86b15fc5f35932bfaeb60e8feac8c7f6639e4fc7eef07ca62672c1f42
MD5 8d16f09a583551d74786d56a354f6e2f
BLAKE2b-256 60684a9dbcf790f48b1b6ea1989b522add121895ff6c0fcdadbe759342ed8237

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page