Abstract
Schemas play a vital role in ensuring data quality and supporting usability in the Semantic Web and natural language processing. Traditionally, their creation demands substantial involvement from knowledge engineers and domain experts. Leveraging the impressive capabilities of large language models (LLMs) in tasks like ontology engineering, we explore schema generation using LLMs. To bridge the resource gap, we introduce two datasets: YAGO Schema and Wikidata EntitySchema, along with novel evaluation metrics. The LLM-based pipelines utilize local and global information from knowledge graphs (KGs) to generate schemas in Shape Expressions (ShEx). Experiments demonstrate LLMs' strong potential in producing high-quality ShEx schemas, paving the way for scalable, automated schema generation for large KGs. Furthermore, our benchmark introduces a new challenge for structured generation, pushing the limits of LLMs on syntactically rich formalisms.
Introduction
Knowledge Graphs (KGs) such as Wikidata and YAGO are foundational to modern AI applications. However, their decentralized and massive nature often leads to inconsistent modeling, redundancy, and noise. To maintain data integrity, developers rely on validation schemas—specifically Shape Expressions (ShEx) or SHACL—which serve as blueprints defining the required properties and data types for specific entity classes.
Manually authoring these schemas for millions of classes is a Herculean task. While automated "pattern mining" tools exist, they often mirror the noise present in the source data rather than defining an ideal structure. This research investigates whether LLMs can leverage their semantic reasoning capabilities to automate the generation of high-quality, human-readable schemas.
Methodology
The authors developed a pipeline that transforms raw Knowledge Graph information into structured ShEx scripts. To ensure syntactic validity, the system uses a Structured Generation approach: rather than asking the LLM for raw code, it prompts the model to output constraints in a structured JSON format (via Pydantic models), which is then programmatically converted into valid ShEx.
Three distinct prompting settings were evaluated to determine the optimal information density for schema generation:
- Local Setting: Provides specific instance examples (e.g., five actual movies) and their immediate neighbors to help the model infer patterns.
- Triples Setting: Focuses on specific predicates and provides example triples where those predicates appear.
- Global Setting: Provides aggregated metadata, including predicate frequency, cardinality distributions, and data type statistics.
Benchmarking Datasets
To evaluate these methods, the study introduced two new ground-truth benchmarks:
- YAGO Schema (YAGOS): Comprising 36 ShEx schemas with 678 constraints derived from the YAGO 4.5 knowledge base.
- Wikidata EntitySchema (WES): Comprising 50 ShEx schemas with 1,874 constraints, manually refined by knowledge engineers from community-curated Wikidata schemas.
Results and Analysis
The performance of LLMs (GPT-4o mini and DeepSeek-V3) was compared against sheXer, a state-of-the-art rule-based baseline. The results indicate that LLMs significantly outperform traditional mining tools by utilizing semantic reasoning over property labels.
Key Findings
- Superior Accuracy: LLMs achieved much higher F1 scores than the baseline. On the YAGOS dataset, GPT-4o mini reached an F1 of 0.591 in the triples setting, compared to sheXer’s 0.092.
- Global Context and Coverage: The "Global Setting" proved most effective at reducing "missing predicates," ensuring that generated schemas were comprehensive by accounting for statistical outliers.
- The Cardinality Bottleneck: LLMs occasionally struggle with precise cardinality (e.g., determining if a property is mandatory or optional). A hybrid approach—combining LLMs for property identification with traditional Machine Learning (like Gradient Boosting) for cardinality prediction—yielded the most robust results.
- Semantic Reasoning: Unlike rule-based tools that rely on frequency, LLMs can recognize that a property like "date of birth" is essential for a "Person" class even if the underlying data is sparse.
Conclusion
This work demonstrates that LLMs are a powerful tool for automating Knowledge Graph schema generation. By bridging the gap between noisy data mining and manual engineering, LLM-based pipelines offer a scalable path toward higher data quality in the Semantic Web. Future work will focus on expanding these benchmarks to include more complex, nested ShEx features and exploring human-in-the-loop workflows to further refine automated outputs.
Summary updated