300-nl2sparql

300-nl2sparql is a cursor rule for Cursor from arango-solutions/arango-sparql-py. It costs 0 tokens per session (621 once invoked), scanned A, original, MIT.

Rules for turning natural-language questions into SPARQL queries, the standard language for asking questions of RDF and OWL knowledge graphs. They provide ontology context, examples, and tenant-isolation checks for multi-tenant systems.

In plain words
What is it for?
Use them when building or reviewing a natural-language-to-SPARQL pipeline, supplying an OWL ontology in Turtle format, adding few-shot examples, resolving entities, and enforcing customer data boundaries.
Why use it?
They constrain generated queries to the SPARQL 1.1 standard and help prevent one customer’s data from being exposed to another. The rules also resolve the final query through an existing translation pipeline.

Cursor rule for Cursor

Written for Cursor: installed under .cursor/.

Good fit Use them when building or reviewing a natural-language-to-SPARQL pipeline, supplying an OWL ontology in Turtle format, adding few-shot examples, resolving entities, and enforcing customer data boundaries.

Compare 6 cursor rules from other repositories ↓
Install with agentmods
npx agentmods add rules/arango-solutions/arango-sparql-py/300-nl2sparql
Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

Clone the repo
git clone --depth 1 https://github.com/arango-solutions/arango-sparql-py

Made for: Cursor.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for 300-nl2sparql

README.md
[![agentmods](https://agentmods.dev/badge/rules/arango-solutions/arango-sparql-py/300-nl2sparql.svg)](https://agentmods.dev/rules/arango-solutions/arango-sparql-py/300-nl2sparql)
Your own site
<a href="https://agentmods.dev/rules/arango-solutions/arango-sparql-py/300-nl2sparql"><img src="https://agentmods.dev/badge/rules/arango-solutions/arango-sparql-py/300-nl2sparql.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for 300-nl2sparql

Your own site · 80×15
<a href="https://agentmods.dev/rules/arango-solutions/arango-sparql-py/300-nl2sparql"><img src="https://agentmods.dev/badge/rules/arango-solutions/arango-sparql-py/300-nl2sparql.svg?style=web" alt="Reviewed on agentmods" width="80" height="15"></a>
Per session 0 Nothing until a file matches its globs; then the whole rule loads.
When invoked 621 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00000 $0.00621
Opus 5 $0.00000 $0.00311
Sonnet 5 $0.00000 $0.00124
Haiku 4.5 $0.00000 $0.00062

Measured 8d ago against content hash 214d952907ee, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-08, from the pricing page.

Security

Grade A, and why

300-nl2sparql scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 8d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

.cursor/rules/300-nl2sparql.mdc · 49 lines

How it starts

The opening of the file, as written. The whole thing — 49 lines — stays where its author put it; the contents beside it link to each section on GitHub.

NL→SPARQL rules

Structure (mirror arango_cypher/nl2cypher/)

  • _core.py — pipeline orchestrator and NL2SparqlResult dataclass.
  • providers.pyLLMProvider protocol + concrete OpenAIProvider, AnthropicProvider, plus the test-only ScriptedProvider mock.
  • fewshot.py — BM25-backed few-shot index over a curated corpus.
  • tenant_guardrail.py + tenant_scope.py — same multitenancy posture as Cypher: physical-tenant collection rewriting and prompt-side scope hints, enforced before the AQL ever runs.
  • entity_resolution.py — optional ER hook (mirrors Cypher's).
  • _aql.py — final AQL emission step (translates the LLM's SPARQL through the same parser/visitor/builder pipeline the /translate endpoint uses; never asks the LLM for AQL directly).

Prompt construction

  • Always provide the OWL ontology in Turtle (.ttl) as the schema context. LLMs read Turtle far better than JSON-LD or XML. Generate Turtle from arango-schema-mapper's OWL output.
  • Prompt header: pin the SPARQL dialect (SPARQL 1.1), forbid vendor extensions, require fully-qualified IRIs (no bare prefixes the model invents), and constrain output to a fenced sparql block.
  • Few-shot examples come from the BM25 index over a curated YAML corpus; never inline more than 3 shots — token budget is real.

Result type

  • NL2SparqlResult carries: sparql, explanation, confidence, method ("llm" | "rule_based" | "cached"), schema_context, prompt_tokens, completion_tokens, total_tokens, cached_tokens, retries. Match Cypher's NL2CypherResult field-for-field where the semantics carry over — easier cross-repo telemetry.

Caching / corrections

  • Persist user corrections in nl_corrections.db (SQLite, WAL mode), identical schema shape to Cypher. Lookups happen before any LLM call.

Forbidden

  • Asking the LLM to emit AQL directly. The LLM's job is SPARQL only; the deterministic transpiler turns SPARQL into AQL.
  • Inlining the entire OWL ontology when a tenant-scoped slice would do — pre-trim the Turtle to the tenant's reachable classes/properties.

Read the full file on GitHub · 49 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 8d ago First seen · 49 lines · 0 tokens per session scan A 214d952907ee

Subscribe to this mod's changes

300-nl2sparql is a cursor rule published in the GitHub repository arango-solutions/arango-sparql-py (2 stars, last pushed 2d ago), licensed MIT. It costs nothing until one of its globs matches a file; then it loads 621 tokens. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.