Ask Safely: Privacy-Aware LLM Query Generation for Knowledge Graphs

Mauro Dalle Lucca Tosi, Jordi CabotarXiv 2025 · DOI

Introduction

Large Language Models (LLMs) have demonstrated remarkable proficiency in translating natural language into formal query languages like Cypher for Knowledge Graphs (KGs). However, their adoption in sensitive sectors like healthcare or law is hindered by significant privacy risks and resource constraints. Sending sensitive data to third-party providers violates privacy policies, while running powerful models locally requires prohibitive hardware resources.

Comparison of KG-based Q&A methods across key requirements.

This paper introduces a privacy-preserving framework that leverages the reasoning power of cloud-based LLMs without exposing actual sensitive values. By sending only the graph's schema and a masked version of the user's question, the authors achieve high accuracy while ensuring data remains local.

Methodology: The Mask-Prompt-Unmask Workflow

The authors propose an integrated workflow within the BESSER Agentic Framework (BAF) that follows a "mask-prompt-unmask" cycle designed to protect data at every step:

  • Schema Extraction: The system extracts the KG's "skeleton"—node labels (e.g., Movie), relationship types (e.g., STARRED_IN), and property keys—while ignoring the actual data entries.
  • Question Masking: A Named Entity Recognition (NER) system identifies sensitive values in user queries (e.g., "Which film did [Will Smith] star in?"), replacing them with generic placeholders like NODE_VALUE or AD_HOC.
  • Synonym Mapping: To help the LLM understand domain-specific jargon, the system maps user terms to canonical graph labels (e.g., "film" becomes MOVIE).
  • Prompting: The LLM receives the graph schema and the masked question. It is tasked with generating a Cypher query using the placeholders.
  • Local Reconstruction: Once the LLM returns the query (e.g., WHERE actor.name = "AD_HOC"), the system locally swaps the placeholders back for the original sensitive values before executing the query against the private database.

Evaluation and Datasets

The approach was evaluated using the METAQA dataset, a benchmark containing over 16,000 movies and nearly 40,000 natural language questions. To ensure the evaluation focused on logic rather than just repeating patterns with different names, the authors filtered the dataset down to 503 unique question patterns.

Key Results and Insights

The privacy-aware method demonstrated that privacy and efficiency can be complementary. By sending only the schema instead of data chunks, the authors reduced the prompt size to under 1,400 tokens, making the process faster and cheaper while protecting privacy.

Accuracy comparison between the proposed privacy-aware method and baselines.

As shown in the results, the privacy-aware method achieved 82.5% accuracy, nearly matching the "no-privacy" baseline of 83.1%. This suggests that LLMs do not need to know the specific identity of an entity to understand the logic required to find it in a graph. Furthermore, when accounting for errors or omissions in the original dataset's ground truth through manual assessment, the effective accuracy rose to 91.0%.

Conclusion and Future Work

This research proves that masking sensitive data results in a negligible drop in performance, proving that cloud-based LLMs can be used safely for private KG querying. Future work will focus on automating synonym definition, testing the approach on more complex, heterogeneous knowledge graphs, and integrating Role-Based Access Control (RBAC) to ensure users only generate queries for authorized portions of the graph.

Summary updated

BibTeX
@misc{tosi2025ask,
  author = {Mauro Dalle Lucca Tosi and Jordi Cabot},
  title = {{Ask Safely: Privacy-Aware LLM Query Generation for Knowledge Graphs}},
  year = {2025},
  eprint = {2512.04852},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2512.04852},
}
Figure