
Build a knowledge graph before you fine-tune the model
Before you fine-tune a model to fix agent errors, check which failure you have. A knowledge graph and an ontology often fix facts, links, and rules first.
Has someone on your team proposed fine-tuning a model because an agent keeps confusing how your products, customers, or policies relate to each other? Once prompting and retrieval stop improving the answers, customizing the model can feel like the obvious next step, although few teams take it. In Menlo Ventures' 2026 State of Enterprise AI report , post-training, which further trains an existing model for a company's own tasks, rose from 6% of AI builders in 2025 to 10%. Menlo attributes the slow uptake to specialized models needing constant updates as frontier models improve. Supplying facts at answer time also tends to beat training them in. In a study by Ovadia et al. at EMNLP 2024 , Mistral 7B answered multiple-choice questions about recent events with 0.875 accuracy through retrieval, compared with 0.504 after fine-tuning on the same material and 0.588 after fine-tuning on paraphrases of it.
In this article, I argue that when an agent fails on facts, relationships, or business rules, a knowledge graph and an ontology are worth building before you customize the model. A knowledge graph stores the entities your business runs on and how they relate, and an ontology defines the types and rules those entities follow. The article covers how to tell which failure you have, what published results show a graph and an ontology fix, where customization still performs better, and why the order matters when the base model changes. No study I found compares the two approaches directly, so the case rests on indirect evidence.
How do you tell which fix an agent failure needs?
The AWS guidance on the generative AI customization spectrum moves from prompting to retrieval to training, and it advises adding the next, more complex step "only when the current step fails your accuracy, latency, or domain requirements." Best practice GENOPS05-BP01 in the Generative AI Lens of the AWS Well-Architected Framework makes the same call, prioritizing prompt engineering and retrieval-augmented generation (RAG) before model customization. Neither places a knowledge graph in that sequence, so the following table is my own version, with the graph sitting between retrieval and training.
Failure you see | Fix to try first | When customization fits |
|---|---|---|
A fact is missing or out of date | Retrieval, with the fact kept in the graph | Rarely, since facts belong in context |
The agent can't connect facts across sources | Graph traversal | Supervised fine-tuning, if errors persist with the right facts retrieved |
The right facts arrive, yet the answer combines them poorly | Structured prompting over the graph | Continued pretraining |
The agent invents attributes or breaks business rules | An ontology with rule validation | Reinforcement fine-tuning, with the rules as the reward |
The format or tone is wrong, or each call costs too much | Prompting and prompt caching | Supervised fine-tuning, or distillation to a smaller model |
To tell which row you're in, consider pulling 50 to 100 failed traces from your evaluation set and checking whether the facts each answer needed reached the model, which Figure 1 walks through as two questions. When the facts never arrived, or arrived without the link between them, the graph is the next investment. When they arrived and the answer still went wrong, the problem sits with how the model reasons over them, and the graph helps there only partly. The first group usually comes down to three things a graph and an ontology hold, which are the facts, the links between them, and the rules they follow.

Figure 1: Two questions about each failed trace separate the failures a graph fixes from reasoning failures
What the graph and ontology fix
Facts change, and a fact in a graph can be corrected in place, while a fact trained into a model has to be edited or retrained. Editing model weights directly is unreliable, as the RippleEdits benchmark (TACL 2024) found that editing methods "fail to introduce consistent changes," while "a simple in-context editing baseline obtains the best scores." Supplying the corrected fact in context is what a graph does, with the related facts stored beside it.
Links between facts matter when an answer needs facts from different passages and no document states how they connect. HippoRAG (NeurIPS 2024) pairs a knowledge graph with the Personalized PageRank algorithm, which ranks entities by how closely they connect to the ones in the question, and outperformed earlier methods on multi-hop questions, which need several facts combined, "by up to 20%." In a systematic evaluation of RAG and GraphRAG , however, ordinary retrieval given the same token budget nearly matched GraphRAG overall, at 71.01 compared with 71.17, and the graph's clearest advantage was on time-based questions, at 49.06 compared with 43.74.
Consider a quoting agent at a software portfolio company that offers a customer a 25% discount on a contract that expired last quarter, which is the kind of rule failure an ontology is built to catch. The ontology can state that every quote references an active contract and that discounts above 15% need an approval record. The same kind of rule applies in other industries, such as coverage limits for an insurance claims agent or dosage limits for a clinical agent. The Shapes Constraint Language (SHACL) , a World Wide Web Consortium (W3C) standard, can check the agent's proposed quote against those rules once the quote is expressed as graph data, as Figure 2 shows.

Figure 2: The proposed quote breaks two ontology rules, so the agent revises it before it reaches the customer
In a 2026 preprint on ontology-grounded agents covering 1,800 runs, agents grounded this way "significantly outperform ungrounded agents" with all three models tested, and the gains were largest where a model's training covered the domain least. The authors built the platform they tested, so read that as a reported result that still needs independent replication.
When is fine-tuning the better fix?
Some failures persist even when the right facts are present. In a 2026 preprint on reasoning failures in graph retrieval , the answer was already in the retrieved context for 77% to 91% of questions, yet 73% to 84% of errors were reasoning failures. Structured prompting over the graph recovered 2 to 14 percentage points. Beyond that, the AWS customization guidance recommends continued pretraining, which trains the model further on unlabeled domain text, when the model "still produces incoherent synthesis" from correct retrieved content. Format, tone, and task structure are behavior problems, and for those the guidance recommends supervised fine-tuning when you can show correct behavior through labeled examples and reinforcement fine-tuning when you can define correctness as a reward. Distillation, which trains a smaller model to reproduce a larger model's outputs, fits when per-call cost limits a high-volume workload.
The strongest result against my view belongs here too. In a January 2026 preprint on multi-hop questions , Mistral 7B scored 0.813 after supervised fine-tuning against 0.654 with retrieval. That retrieval used text passages with no graph, and the authors caution that supervised fine-tuning "may conflate knowledge acquisition with task-specific pattern learning." Fine-tuning can still perform better on a given task, so the useful comparison is what each approach costs you when the model underneath changes.
Why the order matters
A custom model is tied to its base model, because customization often trains an adapter, a small set of added weights that works with one base model. When a new base model arrives, the adapters trained on the old one usually have to be retrained with the original or synthetic data, as the authors of LoRA-X describe. That constant updating is one of the two reasons Menlo gives for slow adoption of post-training. An ontology stored in W3C standards such as the Resource Description Framework (RDF) and the Web Ontology Language (OWL) doesn't depend on any one model, so a model change becomes a re-evaluation of the graph instead of a retraining run, as Figure 3 shows. In the ontology-grounding preprint, the same grounding improved all three models it tested.

Figure 3: The graph and ontology carry across base models with re-evaluation, while each adapter is retrained
The graph also stays useful when you customize later. In COSMO, Amazon's research on product search , a ranking model given relationships from a commonsense knowledge graph improved macro-F1, the F1 score averaged across product categories, by 60% over the best baseline with its encoders fixed, and it kept a 28% edge after fine-tuning. Graph paths and ontology rules can also become the training data or the reward, and MedJudgeRAG found its graph "more effective as graph-conditioned supervision at training time than as an explicit output at inference time." Consider designing the graph for both uses from the start, with access controls at the level of entities and relationships, because a graph can combine data that no single source exposes on its own.
How would you build this on AWS?
Consider building in the three steps in Figure 4 and re-running the same failure-labeled evaluation after each one. GraphRAG in Amazon Bedrock Knowledge Bases builds an entity graph from your documents in Amazon Simple Storage Service (Amazon S3) on Amazon Neptune Analytics, which makes it a quick test of whether connection failures drop. It doesn't let you customize how the graph is built or apply an ontology of your own. When rule failures dominate, Amazon Neptune Database holds a modeled graph, and the open-source Context Ontology Accelerator induces and manages OWL ontologies, checks context against business logic, and serves it to agents through the Model Context Protocol (MCP). When a failure still calls for customization, Amazon Bedrock supports model customization through supervised fine-tuning, reinforcement fine-tuning, and distillation for supported models, and the graph you already built can supply the examples or the reward.

Figure 4: Three build steps on AWS, with the same failure-labeled evaluation after each one
If you've tried building a graph before customizing a model, or the other way around, I'd like to hear what your evaluation showed in the comments.
About the author
Michael Purpura is a Senior Global Private Equity Solutions Architect at AWS. He works with private equity firms and their portfolio companies to structure AI adoption around measurable business outcomes.
Enjoyed reading this content? Let the author know!
Your likes, comments, shares, and saves help creators reach more builders.
Loading recommendations
Loading article