Frank Coyle of UC Berkeley shows AI Engineer how to enforce domain rules at the points where an agent calls tools and reads their results.
Check both sides of a tool call
- The model proposes a tool and its arguments. The software around the model decides whether that call runs and what result goes back into the loop.
- Check the proposed input before anything happens. After execution, check whether the result fits the domain before passing it back as evidence. A result check cannot undo a write.
- Claude Code hooks offer both points in an existing agent. A
PreToolUsehook can block a call. APostToolUsehook can inspect what happened.
Get people to agree on their terms first
- Coyle asks whether a hot dog is a sandwich. A recipe archive and a lunch counter can draw that boundary differently. An automated rule needs an answer for the job it does.
- An ontology spells out what kinds of things a domain has and how they relate. Start with a glossary and its aliases, then define classes and relationships. A knowledge graph records the specific facts you have about them.
- Reuse terms where the meanings match. Coyle’s Onto-Explorer helps teams compare vocabularies such as Schema.org, FOAF and SKOS before inventing their own.
Separate inference from enforcement
- RDF Schema can infer that someone on the ordering side of an
ordersrelationship is a customer. That inference alone does not reject a bad record. - Pydantic can check the format of a refund identifier. SHACL can check required fields and value counts in a graph. SPARQL can query the graph for supporting evidence.
- The application still has to decide whether a result can be used or an action can proceed. Rules only cover the domain the team has modeled.
“Probabilistic reasoning on the inside, logical constraints on the outside.”