~6m26:36
AI Engineer

Ontologies as Guardrails for Agents — Frank Coyle, UC Berkeley

Nov 29, 2026

Read: ~6m · You save: 21 min

Ontologies as Guardrails for Agents

Why do LLMs need guardrails? Frank Coyle links the agent loop, neurosymbolic AI and ontologies, from RDFS and OWL to SHACL, and asks: is a hot dog a sandwich?

Frank Coyle, UC Berkeley

Two Lineages: Agentic AI and Ontologies

AI has produced two lineages. The first is agentic AI. Its roots lie in early AI research. John McCarthy defined the term "artificial intelligence." Marvin Minsky developed the concept of the Society of Mind. Researchers began exploring these ideas at that time.

The second lineage is ontologies. The term traces back to ancient Greece and Aristotle's theory of being. Its meaning changed over time. Willard Van Orman Quine addressed the value of a bound variable. Thomas Gruber defined an ontology as "a formal specification of a shared conceptualization."

Neurosymbolic AI combines these two lineages. It pairs the large language model (LLM) world of agents with formal logical systems based on ontologies. In short, probabilistic reasoning operates on the inside, and logical constraints operate on the outside.

Why LLMs Need Guardrails

LLMs do not store facts. They are not databases. They absorb large volumes of material from the web, documents, books, and websites.

LLMs operate in a multi-dimensional latent space defined by embeddings. Each embedding consists of 4,096 numbers. These numbers represent points in that space. The model makes its decisions by locating points in this space to determine what the user wants. It does not look up facts.

Hallucinations are not a defect. They result from the probabilistic design of the system.

A useful way to describe an LLM is a "brain in a box." It takes tokens in and produces tokens out.

Why the Loop Matters

Concern about LLMs stems from their ability to loop. Böhm and Jacopini proved that any language with sequence, conditionals (if-then), and loops is Turing complete, meaning it can compute anything that is computable. LLM systems give the model control over loops. Practitioners treat loops as the core design paradigm. Boris Cherny describes his job as writing loops. Peter Steinberger designs loops that prompt agents.

Anatomy of the Agent Loop

The agent loop has the following components:

  • Python code: Executes the actions.
  • Prompt handler: Converts the user's prompt into tokens and feeds them to the LLM.
  • Tool definitions: The tools available to the agent are passed to the LLM together with the prompt.
  • LLM: Decides which tool to use and which parameters to apply. It cannot execute actions itself.

The sequence runs as follows. The code runs the requested tool and returns the result. The result goes back to the LLM, which converts it into a final response.

The LLM reports a stop reason each time it stops. Possible reasons include task completion, exhaustion of tokens, and a request to call a tool. If the stop reason is not a tool use, the process ends. If it is a tool use, the system executes the tool call.

Placing Guardrails in the Loop

Viewed as a data flow, the agent loop can be split into discrete steps. Data flow diagrams have modeled systems effectively since the 1960s. Guardrails can be placed between these steps. The main checkpoints are:

  1. Input validation: Check the shape of the input passed to a tool.
  2. Output validation: Examine the tool output and confirm that it matches the intended semantics.

Major frontier model providers offer hooks as a native guardrail mechanism. Claude, from Anthropic, provides hooks as one example. Anthropic changes these features over time, so implementations must be verified against current documentation. Hooks fire on events, including:

  • Session events: Session start and session end.
  • User prompt submit: Triggers processing when a user submits a prompt.
  • Permission request.
  • Pre-tool use: Fires before a tool call.
  • Post-tool use: Fires after a tool call.

Hooks allow developers to add control without modifying the application code.

Ontologies: Definitions and Shared Meaning

Ontologies define the terms that a system uses and the relationships among them. The speaker illustrated the need for shared definitions with the question "Is a hot dog a sandwich?" Definitions differ across people and contexts, so an ontology must establish agreed terms.

Building an ontology follows a layered sequence:

  1. Taxonomy: Agree on the glossary. Identify the terms an organization uses and define synonyms.
  2. Ontology: Define classes and attributes that enable reasoning.
  3. Knowledge graph: Record the facts and details of the domain.
  4. Guardrails: Enforce constraints and rules.

Jump-Starting an Ontology

Existing ontologies provide a starting point. Examples include:

  • schema.org: Defines orders, customers, and other standard concepts.
  • FOAF (Friend of a Friend): Models knowledge in social networks.
  • SKOS: Defines how to specify concepts and arrange them.
  • PROV-O: Models provenance. It has three core concepts: entities, activities that generate entities, and agents (human or computer-based) that validate them.

Reuse of these terms accelerates development. The speaker noted that expert systems faltered because they did not scale. An ontology avoids that limit because the expertise resides in the organization's own staff, who identify the rules that govern its processes.

Two approaches apply:

  • Top-down: An expert defines the details.
  • Bottom-up: Customer questions and the terms customers use define the content.

The speaker built a tool named TO Explorer, available on the Code Supreme AI website. The tool accepts a domain description and optional documents. It returns relevant existing ontologies, a description of each, and associated terms. For example, FOAF returned 12 related terms.

Structuring Hierarchies and Properties

Hierarchies organize concepts through subclasses. A customer is a kind of person. An elite customer is a kind of customer and also a kind of person.

RDFS defines properties. Declaring a relationship such as "orders" with a domain of customer and a range of product allows a system to infer that the entity on the left is a customer and the entity on the right is a product. Each inference creates new triples, which form the basis of the knowledge graph.

OWL (Web Ontology Language) adds further property types:

  • Transitive properties: If Denver is in Colorado and Colorado is in the USA, then Denver is in the USA.
  • Inverse properties: A relation such as "orders" can be flipped to "ordered by," enabling queries in either direction.
  • Functional properties: Allow only one value for a given subject.
  • owl:sameAs: Merges two terms so that both names refer to one entity.

In knowledge graphs, a relation is itself an entity. It can carry its own properties, such as creation date and source. This feature provides provenance for every relation. In relational databases, by contrast, a relation only connects two entities.

Supporting Tools

The following tools support guardrail implementation:

  • Pydantic: Validates that data is well formed. For example, a refund field can require a value matching a regular expression, and the system can reject non-matching LLM output.
  • SHACL: Checks the shape of JSON data, including minimum and maximum counts that enforce fields.
  • SPARQL: The query language for relationships. It frames questions against the knowledge base.
  • SWRL: Defines logical rules that establish policy.

For policy and governance, the speaker recommended ODRL and PROV-O.

Conclusion

The speaker's guiding principle is "Nothing is a mistake. There's no win and no fail, only make." The principle comes from Sister Corita Kent and was popularized by avant-garde musician John Cage.

Opening and Two Lineages

Coyle opens with a nostalgic link between the 1983 West Coast Computer Fair and today's AI boom, framing the talk around two lineages: agentic AI and ontologies.

  • Coyle spoke in San Francisco and compared the current AI excitement to the 1983 West Coast Computer Fair.
  • At the 1983 fair, Intel's 8080 and Motorola's 6502 chips fuelled hobbyist excitement, including Steve Wozniak and Steve Jobs with the Apple II.
  • Agentic AI traces back to John McCarthy's coining of 'artificial intelligence' and Marvin Minsky's Society of Mind.
  • Ontologies trace back to Aristotle's theory of being, with Quine's bound variable and Gruber's definition: a formal specification of a shared conceptualization.

Neurosymbolic AI and Why LLMs Need Guardrails

Neurosymbolic AI combines probabilistic LLM reasoning with logical constraints from ontologies. LLMs do not store facts; they operate in a latent embedding space, so hallucinations are a by-product of the system.

  • Neurosymbolic AI is summarised as probabilistic reasoning on the inside and logical constraints on the outside.
  • Coyle states LLMs are not databases and do not look up facts.
  • Embeddings are described as 4,096 numbers representing points in a latent space.
  • Hallucinations are described as part of the probabilistic system rather than a flaw.
  • LLMs are described as 'brains in a box' with tokens in and tokens out.

Why Loops Matter

Coyle argues that the loop, not raw intelligence, is what makes LLMs powerful and worrying. Citing the Böhm-Jacopini result, he says sequence, conditionals and loops make a language Turing complete.

  • Böhm and Jacopini showed that languages with sequence, conditionals and loops are Turing computable.
  • Coyle says LLMs have been given the power to control loops, which explains concern about them.
  • Boris Cherny is quoted as saying 'my job is to write loops'.
  • Peter Steinberger is referenced as saying to design loops that prompt your agents.
  • Early language rivalry is mentioned: COBOL for data, Fortran for science, Lisp for AI.

The Agent Loop and Guardrail Opportunities

The agent loop is described as a sequence in which the LLM receives prompts and tool definitions, returns a stop reason and tool-use requests, and tool results are fed back. Each step is a point where guardrails can be applied.

  • The Python code takes the prompt, turns it into tokens and feeds it to the LLM together with the list of available tools.
  • The LLM cannot act itself; it returns the tool to use and its parameters, and the code executes the tool.
  • Results are fed back to the LLM, which phrases the final answer.
  • A stop reason indicates why the LLM stopped; if it is not tool use, the loop can end, otherwise the tool call is made.
  • Input to a tool can be validated for shape and tool output can be checked for semantics.
  • The loop can be modelled as a data flow diagram, a technique dating to the 1960s, to place guardrails between steps.
  • Claude's hooks provide events such as session start and end, user prompt submit, permission request, pre-tool use and post-tool use, without changing code.

Ontologies and the Hot Dog Example

Coyle introduces ontologies through Aristotle's question of being and a hot dog example to show that shared definitions are needed. He proposes a ladder from taxonomy to ontology to knowledge graph to guardrails.

  • Aristotle is cited with 'All men by nature desire to know' and the question of the nature of being.
  • The audience is asked 'Is a hot dog a sandwich?'; a barbecue anecdote from Chicago shows definitional disagreement.
  • The ladder is: taxonomy (agree on glossary and synonyms), ontology (define classes and attributes for reasoning), knowledge graph (actual facts), then guardrails (constraints and rules).
  • Existing ontologies to reuse include FOAF (friend of a friend), schema.org (orders, customers) and SKOS.
  • Coyle describes the 'ontology pick and roll': pick established terms, then roll to the hoop.
  • Expert systems are compared; they faded because they did not scale, but the expertise now lies in the organisation's own rules.

Building Hierarchies, Properties and Relations

Coyle explains how to build an ontology with hierarchies, subclasses, RDFS domains and ranges, and OWL properties such as transitive, inverse, functional and sameAs. In knowledge graphs, relations themselves become entities that can carry provenance.

  • Hierarchies are described as object-oriented: a customer is a kind of person and an elite customer is a kind of customer.
  • RDFS defines domain and range; for 'orders', the domain is customer and the range is product, enabling inference of new triples.
  • OWL transitive property example: if Denver is in Colorado and Colorado is in the USA, Denver is in the USA.
  • OWL inverse property example: 'orders' flipped becomes 'ordered by'.
  • Functional properties allow only one value; owl:sameAs merges two names referring to one entity.
  • In knowledge graphs, a relation is itself an entity with its own properties, such as creator, creation date and source (provenance).

Tools and Guardrails

Coyle presents a set of tools that act as guardrails: Pydantic for validation, SHACL for data shape, SPARQL for querying facts, SWRL for logical rules, plus ODRL and PROV-O for policy and provenance.

  • Pydantic validates that data is well formed, for example a refund field matching a regular expression.
  • SHACL checks the shape of data, including min and max counts that enforce fields.
  • SPARQL is the query language for asking questions of the knowledge base.
  • SWRL allows logical rules to define policy.
  • ODRL is suggested for policy and governance; PROV-O for provenance.
  • Coyle's tool 'Ontology Explorer' is hosted on his site, Code Supreme AI, and named as an homage to John Coltrane's A Love Supreme.

Conclusion

Coyle closes with his teaching philosophy, attributed to Sister Corita Kent and popularised by John Cage: nothing is a mistake, there is no win and no fail, only make.

  • Coyle's teaching philosophy: 'Nothing is a mistake. There's no win and no fail, only make.'
  • The philosophy is attributed to Sister Corita Kent and was popularised by avant-garde musician John Cage.
  • He ends with the call: when you have a hot dog, think ontology.