← All transcripts

Ontologies as Guardrails for Agents — Frank Coyle, UC Berkeley Transcript, AI Summary & Key Points

AI Engineer · yesterday · Science & Technology · 26:37 · EN

Watch on YouTube

Answer

Ontologies act as guardrails for agents by wrapping logical constraints around probabilistic LLMs, with checks placed before and after tool execution in the agent loop, enforced via Claude Code hooks and validation tools like Pydantic, SHACL and SPARQL.

AI Summary

Ontologies add logical constraints around probabilistic LLMs, giving agents the guardrails their valid-but-unchecked tool calls lack. Neurosymbolic AI combines the two lineages: probabilistic reasoning on the inside, logical constraints on the outside. LLMs don't store facts — they make decisions in a latent space of embeddings (4,096 numbers), so hallucination is part of the system, not a flaw. What makes them dangerous is the loop: Böhm and Jacopini proved that sequence, conditionals and loops make a language Turing-computable, and giving LLMs control of loops makes them capable of anything computable. The agent loop can be viewed as a data flow diagram, and guardrails fit between the steps — validate tool input shape before execution and output semantics after. Claude Code hooks (session start/end, user prompt submit, permission request, pre-tool use, post-tool use) expose these checkpoints without touching code. Building an ontology starts with agreeing on a glossary and taxonomy (the hot dog sandwich debate shows why shared definitions matter), then classes and hierarchies, then a knowledge graph of facts, then constraint enforcement. Reuse existing ontologies — FOAF, schema.org, SKOS, PROV-O for provenance — and OntoExplorer, a tool on codesupreme.ai, surfaces relevant existing ontologies for a domain description. RDFS infers types from relations (domain customer, range product), OWL adds transitive, inverse and functional properties, and knowledge-graph relations are themselves entities that can carry provenance. Validation stacks: Pydantic for well-formed data and regex fields, SHACL for JSON shape with min/max counts, SPARQL to query whether a claim holds, SWRL for logical policy rules, plus ODRL for policy and PROV-O for provenance.

Key Points

  • Neurosymbolic AI combines agents with formal logical systems: probabilistic reasoning on the inside, logical constraints on the outside.
  • LLMs don't store facts or look them up — decisions happen in latent space defined by embeddings of 4,096 numbers, so hallucination is part of the system, not a flaw.
  • LLMs are 'brains in a box': tokens in, tokens out; the surrounding Python code turns prompts into tokens, offers tools, executes the tool the model selects, and feeds results back.
  • Böhm and Jacopini proved that sequence, conditionals and loops make a language Turing-computable — giving LLMs control of loops makes them capable of anything computable, which is why people are concerned.
  • Treat the agent loop as a data flow diagram (a modeling technique dating to the 1960s) and put guardrails between the steps: validate input shape before the tool runs, validate output semantics after.
  • Claude Code hooks expose guardrail checkpoints — session start/end, user prompt submit, permission request, pre-tool use and post-tool use — without modifying code; Anthropic changes these over time.
  • Build ontologies in a ladder: glossary and synonyms first, then taxonomy, then ontology with classes and attributes for reasoning, then the knowledge graph of facts, then guardrails enforcing constraints and rules.
  • Jump-start ontologies by reusing existing ones — FOAF for social networks, schema.org for orders and customers, SKOS for concepts — picking top-down from experts or bottom-up from the terms customers use.

AI in practice

Agents

  • Fulfill a user request by selecting and calling tools 2 held 07:27

Business ideas

Wrap an agent's tool-calling loop with formal logical constraints: validate the shape and semantics of tool inputs and outputs, and encode domain rules in a lightweight ontology and knowledge graph so probabilistic model behaviour is checked by deterministic logic — probabilistic reasoning on the inside, logical constraints on the outside.

For
Teams deploying LLM agents against real tools and data who cannot accept hallucinated or domain-invalid tool calls, e.g. regulated or operational workflows.
Solves
An agent can produce a syntactically valid tool call that still violates the rules of the domain. LLMs don't store facts — they reason in latent space, so hallucination is inherent, and once the model can drive loops it is Turing-computable and hard to bound. Hooks and ontology validation let you intercept and reject invalid calls without editing model behaviour.
  • Schema.org reused for orders and customers
🔒  Build steps and tools for 1 idea. Unlock

Tools & resources

1 item

Links mentioned

🔒 Full analysis locked

Unlock more videos and the full analysis

A credit unlocks one video's full analysis for good — the build steps, the tools and how each was used, the methods behind every use case. Pro opens the whole library instead, and raises how many videos you can analyse a day.

Unlock full analysis — free

Transcript

Searchable transcript of Ontologies as Guardrails for Agents — Frank Coyle, UC Berkeley — AI Engineer (26:37). Search for a phrase, then click its timestamp to jump straight to that moment in the video.

Captions sourced from the original video on YouTube, published by AI Engineer. The video, its captions and all related intellectual property remain the property of their respective owners; AINotes claims no ownership. Provided for research, accessibility and search — see the Transcript Notice and Copyright Policy.

00:13 Uh thank you everybody. Uh good to see you all. Happy to be here in in San Francisco. Great hotbed of technology. You know you know I thought like last night I was thinking about this conference and about how we're all here and the focus is on AI, right? That's what we're all up to. And it was back in 1983 and I came here to San Francisco because an exciting technology was just exploding just like it is here.

00:47 And the event that brought me there was the uh the West Coast Computer Fair. And the West Coast Computer Fair was this fair with tables and the big thing was the chip. So it was the beginning it was when Intel released this 8080 chip. Motorola put out the 6502 and all the young hackers were putting their boards together and that's where Steve Wozniak came with Steve Jobs showing how they put the board into the Apple II and a great flood of excitement was around that.

01:29 And I 'm seeing the same thing here now except we're not focused on the chip. We're focused on what the chip has given us. AI and large language models. So that's what my talk is about. So we are in a world where AI has given us what I call two lineages. On one side you have agentic AI. And this goes back to the days of AI. John McCarthy defined the term artificial intelligence.

02:04 Marvin Minsky had something called the Society of Mind, and people were beginning to explore these ideas. On the other side was ontologies. Now, ontologies is is a term that scares a lot of people. It comes it it goes back to the early days of the Greeks, Aristotle, the theory of being, right? And there were some changes over time, how people thought about it.

02:31 Quine, the value of a bound variable. But Gruber's definition, a formal specification of a shared conceptualization. And that's what we need now given the fact that we are in the world of a probabilistic AI. So what we're seeing now is a is a new term that's arising, neurosymbolic AI. So neurosymbolic AI combines the large language model universe of agents with [clears throat] more formal logical systems related to ontologies.

03:10 So one way to think of it is probabilistic reasoning on the inside, logical constraints on the outside. So why do we need this? Why do we need knowledge to clarify things when interacting with the large language models? Aren't these guys super intelligent? Is everybody talking about AGI, super intelligence going to take over the world? Why are we concerned about it?

03:44 These things are so smart. Why do they need why do they need guard rails? Well, the bottom line is LLMs, as you know, don't store facts. It's not a database. LLMs have consumed all this knowledge that's out there, the web, documents, books, websites, everything is brought into its little universe. And it turns out that it you may thinking, I'm not quite sure I want to go down that that that road, but it lives in a multi-dimensional space, a latent space defined by the embeddings.

04:23 Your embeddings are 4,096 numbers. What do these numbers represent? They represent points in space. And that's where the LLM is trying to make its decisions, trying to figure out what you want. Okay? It's not looking up facts. Hallucinations are not a flaw. They're part of the system because they're probabilistic. We are not little fact machines. We dream of the future.

04:54 We think about things that are outside the realm of where we are. And so this is what LLMs are doing, whether we like it or not. So what one way I like to think about it is LLMs are just brains in a box. Tokens in, tokens out. That's who they are. That's what they are. So the question now arises, why are people so freaked out about large language models?

05:30 It's going to take over the world. This little guy is going to going to dominate us. Why are we now thinking that way? The answer is these little guys can loop. We all talk about loops and stuff. Why what is loop what is the loop bring to the table? What does it bring to the equation? Let's go back a few years. The early days of programming languages, people were having great battles.

06:05 My programming language, COBOL, is the best programming language for data. No, Fortran is the best language for science. Lisp, oh, Lisp, the parentheses language of John McCarthy. This is the language for AI. Which is best? Two guys, Beam and Jacopini, did a proof. They said any language that has sequence, do this, do that, do that, conditionals, if then, and loops are Turing computable, meaning they are capable of computing anything that is possible that can be computed.

06:47 So what we have done with these LLMs is we've given them the power to control loops. And that's why since they can do anything that can be computed, people are a little concerned because you've got people using them, which are which is the issue. But if you think about the loop as the paradigm, you have Boris Cherny saying, my job is to write loops.

07:12 And Peter Steinberger of you know, the Open Law, design loops that prompt your agents. So I wanted to drill down a little bit on this concept just to give you a context for where we're going to go. Behind the scenes, what does the loop look like? I'm going to show you what a loop really looks like inside. So if you think about it, there's our brain in the box sitting there on a table, surrounded by these little characters.

07:44 That's our Python code. That's the code that does things. And what's the job of this little guy on the left? His job is to take your prompt, turn it into tokens, and feed it into the brain in the box. Now, in addition to feeding in your prompt to the brain in the box, what's also being fed in is the fact that tools are available. So we say hey, LLM, here's what the user wants.

08:13 Here are the tools I have available. What should I do? Because these little guys don't have any clue what the user is asking. They're just turning it into tokens, feeding it in. LLM says, okay, here's what you want to do. You give me 10 tools. Use tool B and here are the parameters that I want you to use. I can't do anything. I'm just the brain in the box, but you guys can.

08:37 So it passes that information. Then they go off. They they run the code, come back and say here's the result. Feed it back into the LLM who takes that result and turns it into a very nice nicely worded. Oh, you're such a nice person. You're such a genius. Uh here's the here's your answer. Okay? So this is really how things work. So how does this help us with control and organization?

09:09 Think of the agent loop as a data flow. Just take that structure of a while loop and if you split it out, you come you come to what historically has been a very effective way to model systems, a data flow diagram. Been around since the '60s. But if you think of the loop as a data flow, then you now have the opportunity to put your guard rails between the steps of the loop.

09:44 And that's where you can control what may be happening with the LLM. Okay? So that's your guard rail opportunity. So if you look at a little code, here's just the while loop that calls uh that calls an LLM. This little uh what you'd be be doing when you have an API. So you're basically making a call. You're passing the the user's request in, response comes out.

10:13 And and the way the LLMs work, when they stop, they tell you why they stopped. So there's a stop reason. A number of stop reasons and this is a very very foundational example, but there are a number of reasons why the LLM stops. One is I've done what you want to what you asked me to do or you know, you've run out of tokens. So I'm stopping because I'm you're not paying for more, okay?

10:39 Or you asked me to run a tool and here's what you should do. So there are a number of reasons why it stops. So you look at the reason and you say, okay, if the stop is not equal the tool use, something else I can get out of here. But if it is, then okay, go make the tool call. Go make the tool call. So it you can make the tool call and then this gives you an opportunity to check.

11:09 You can check, you validate the shape of the input going into the tool and then when the tool does its work, you can examine the output and see if it matches the semantics of what you're doing and validate the result. And so there are some some some tools I'm going to show you about Sparkle and Shackle and so forth that can help you do this. Now what's interesting is this has not been lost on the major frontier models who give us a very significant feature called hooks.

11:42 So hooks, think of the hook as the guard rail opportunity. So Claude and Claude you know, Claude Anthropic changes these over over time. So you have to be careful, but right now it's it's a very interesting model. They launch events when you do any one of these things. So there are session events. The session starts. The session ends. But over when you're prompts, user prompt submit, you are be- you can set up a hook so you're notified the user is submitting their prompt.

12:21 Okay, opportunity to do some processing. There's a permission request. So all these things are available to you now without having to insert stuff into the code itself. You can just define hooks. Um if so there's pre-tool use. Every time a tool is getting ready to call a pre-tool event is fired and you can catch that event and you can do something with it.

12:53 Post-tool use. You can grab that event and do something with it. So just be aware of the uh the fact that these services are available with with Claude and with a number of the other the other models. Okay, so that's that's part A of of this talk just kind of set things up what the LLM is and how it works. On to ontologies. Okay, ontologies is the big word.

13:31 Aristotle. All men by nature desire to know. What is the nature of being? Okay, these are pretty heavy-duty philosophical questions. But I wanted to take a second here and I want you guys to answer a very important ontological question that will set the stage for anything you want to do with ontologies. So put on your your philosopher hat and I'd like you to think about the answer to this question.

14:07 Is a hot dog a sandwich? Okay. Now I gave this talk in Chicago. I I gave part of it in Chicago. And after the talk, a woman came up to me and said, you know, I was having a barbecue last weekend, and I my husband was in charge of the barbecue, and he was going to cook hamburgers and hot dogs. And when I got out there, I noticed that he forgot to buy the hot dog buns.

14:35 And I said to him, honey, there are no hot dog buns here. And he said, don't worry. We'll just put the hot dog between two slices of bread, and that'll be fine. And that was almost the end of their marriage, discussing what defines a hot dog, okay? So the reason this is this is significant is because when you're trying to build an ontology, a knowledge base, get the definitions in place and have everybody agree on the definitions.

15:05 Cuz does anybody think hot dog is a sandwich? How about not a sandwich? I mean if if you go into a sandwich shop and order a ham order a beef sandwich, you're not going to If you the guy gives you a hot dog, or if you go to a hot dog stand and they're going to give you a sandwich, you're going to be upset. Okay, so I've created I haven't created it, but I thought about approaching the the problem with a ladder, sort of a hierarchy.

15:33 At the bottom is technology. So uh taxonomy. So is a hot dog a sandwich? Agree on your glossary. What is your What are the terms that your organization uses for something? A lot of times there are different terms. Okay, that's fine. Define Define the synonyms, okay? See, once you have your techno your your taxonomy, then we're going to move to the ontology, which is where we're going to define classes and attributes that enables reasoning.

16:05 Then from there, you can build a knowledge graph, the actual facts, the actual details of your domain. And once that's done, you can think about adding guard rails, enforcing constraints and rules. So, how do you go about jump starting this process, which is one of the problems that I'm kind of working on cuz a lot of people have a hard time getting started with this whole process.

16:31 What I want you to be aware of is that there are a number of existing ontologies out there, schema.org, FOAF for friend of a friend. So so the idea is take advantage of what is out there, what has been developed over time and use use that use those terms. Um and in a way this this this models expert systems. This may be this is a way you know expert systems.

16:58 I was involved in expert systems early on and uh they kind of faded away because they didn't scale. But we're not having to scale the expertise. The expertise is you in your organization to finding the to finding the rules that are going to be used for your processes. Okay? And you can get it from a top down, get an expert to come up with the the details or you can do bottom up.

17:25 Look at what are your what are your customers asking you? What are the terms they're using? That should be in in your ontology. So I like kind of crazy analogies. So I've created this. I used to play a lot of basketball. I call it the ontology pick and roll. Any basketball players in here? Anybody? So you know the pick and roll. Somebody picks and then you roll.

17:49 So the idea here is you pick from pick from established terms and you roll to the hoop and get a slam dunk. The analogy is not perfect, but it's hopefully you'll it'll it'll help you. So um start by borrowing terms from existing ontologies. There's something called FOAF, friend of a friend, and it was modeled to it's to uh represent knowledge in social networks.

18:19 schema.org has a lot of stuff. They define orders, customers, all the kind of standard stuff. And there's something called SCOs, which has uh conceptual how to define concepts and arrange them. So take advantage of this. So I recently put this little program together, which is available. You can go there now on TO Explorer on my uh website Code Supreme AI, which is actually an homage to John Coltrane, who wrote uh Love Supreme.

18:53 I don't know if you have any JS people out there, but uh but this this little program lets you uh lets you enter a description of your domain and also has a couple of sample domains that you can uh you can select and it'll put some information up there. And then uh what you'll get is this little screen and you can scroll down and it'll give you the relevant existing ontologies that pertain to the description that you put in that text box.

19:24 You can put documents in there, too. It just give you an idea of of sources of naming, cuz that is often the difficult part, attaching the the the key names to your ontology. So you can see how in this little example uh looks like FOAF is had 12 terms that are are related in SCOs and and you can uh uh I find it useful or people find it useful cuz you can scroll down and when you hit each of these ontologies, it gives you a little description on the right what they're what they're designed to do and what some of the

20:00 terms are you know, that are associated with it. So here's another one. There's one for provenance, which is a big deal uh where things came from. And it has three core ideas which are the have that how in provenance you have entities and you have activities that generate the entities and then you have agents, either human or computer-based that will that validate that.

20:26 So that can be quite useful. So that's your taxonomy. What about the ontology part? Ontology part means take these terms and define hierarchies. Hierarchies are huge. Human human beings, we love hierarchies. We're always establishing hierarchies. Companies have hierarchies. Uh services have hierarchies. So a person customer think think object-oriented.

20:52 This is object-oriented kind of stuff with hierarchies, subclasses. So a customer is a kind of person and an elite customer is a kind of customer and also a kind of person. So these are some of the things. And then you then you define your properties. So there are some tools available. Something called RDFS. So let's say uh somebody you're trying to define the relationship between a customer and a product.

21:23 So a customer orders a product. So you define this relationship orders. Then with RDFS, you can say and whenever I see an order I can infer that the create that the entity on the left side is a customer and the entity on the right side is a product. With this RDFS, the domain is customer the range is going to be a product. And now you're inferencing.

21:47 You're creating new sets of of triples, which is what the basis of uh you know, the knowledge graph is. And this now gives you additional information that lets you then establish queries about that. With a technology called OWL, the the Web Ontology Language with your properties, you can say this is a transitive property which means if uh if the if Colorado is in the USA and Denver is in Colorado, then I can infer that Denver is in the USA.

22:28 The property transfers down. You can set up inverse property. So, often we define our relations in in one way, like Anna orders a mug, but then you can specify if you flip it, then the property changes to ordered by. And this lets you have established queries. Who's everyone who ordered my where ordered by you can you can change your phrasing. But your facts flip both ways.

22:59 Then you can have functional properties, which means there's really only one. And if you have two terms, then owl:sameAs will merge them together and two names will refer to one entity. And there are a number of things like that that you can do. Now, what's what's interesting to me about this is that that a lot of people don't realize is that the properties you go back to you know, the entity relationship diagrams of of the of the relational database world, basically the relation just connected two things.

23:34 In knowledge graphs, the relation or the relation is itself an entity which can have its own properties. So, if I define a property called orders, then I can attach to that the creator. When was this created? What's the source of this information? You can get provenance for all your relations in there. So, this is a feature that you get when you set things up in this in this in this format.

24:08 And then the the next part is is the knowledge graph, which is the facts that are in the system. Okay. So, I just want to go over the tools real quickly. So, these are some of the supporting tools that are available. Pydantic that can help you if the the data is well formed. Shackle, does the the data fit the shape? Sparkle helps you ask, does the claim true?

24:33 Swirl allows you to put rules in there allowing defining the policy. So I've got a couple of slides a little more detail, but basically these are some of the guardrails that you can put in. So pedantic will catch will let you catch validation errors. You say my uh my refund must have a field that is defined by a regular expression. So if the LLM gives you something that doesn't match, you can catch that.

25:01 Shackle is a guardrail of the shape of your JSON. Can check the shape. Have min counts, max counts. These enforce your enforce your fields. Sparkle is the query language for these these relationships. And you can frame questions, ask about ask about the knowledge base. And then you can have rules, logical rules set up, this rule language. So all these things surround the ontology.

25:28 So take advantage of this uh universe of of terms. Okay, about running out of time, but what about policy and governance? There are other tools. Take a look at ODRL. Take a look at PROV-O for provenance. Do a search. You'll get it all. So I'm going to conclude here with my teaching philosophy, carry it forth. Nothing nothing is a mistake. There's no win and no fail, only make.

25:59 This comes from Sister Corita Kent. Was made popular by John Cage, avant-garde musician. So if you want the Anto Explorer and my site there you go. Okay. Thanks a lot. Go forth and when you have a hot dog think ontology. >> We