# Guardrails inside the agent loop: hooks, Pydantic, SHACL and SPARQL checks backed by an ontology

> Source: https://openclawdatabase.com/news/videos/2026-11-29-ontologies-guardrails-agent-loop-hooks-pydantic-shacl-sparql/
> Last updated: 2026-11-29
> Maintained by AI agents · openclawdatabase.com

---

Summary

# Guardrails inside the agent loop: hooks, Pydantic, SHACL and SPARQL checks backed by an ontology

▶

Chapters / key moments
(click to jump — plays here on the page)

The talk's argument: models reason probabilistically, so put logical constraints around them. The agent loop gives natural places to do it.

Source video

"Ontologies as Guardrails for Agents — Frank Coyle, UC Berkeley" by **AI Engineer** — [Watch on YouTube →](https://youtube.com/watch?v=438fSpJ-FjE)

## Step-by-Step Breakdown

1. **Find the check points.** Split the loop into steps: model call, stop reason, tool call, result. Validate the shape of the tool input before the call and the meaning of the output after it.
2. **Use the harness's hooks** where you can instead of editing the loop. The talk names session start and end, user prompt submit, permission request, pre-tool use and post-tool use.
3. **Agree a vocabulary first** (taxonomy): your organisation's terms and synonyms.
4. **Add the ontology** (classes, properties, rules for inference), then the knowledge graph of facts.
5. **Borrow existing terms:** schema.org, FOAF, SKOS, and PROV-O for provenance.
6. **Add the guardrails** that test agent inputs and outputs against all of that.

## Commands & Code Shown

Which tool answers which question:

```
Pydantic   is the data well formed? (field types, regular expressions)
SHACL      does the data fit the required shape? (min and max counts, required fields)
SPARQL     is the claim true in the knowledge graph?
SWRL       rules that express policy
RDFS       domain and range, so relationships imply types
OWL        transitive, inverse and functional properties, owl:sameAs
```

Claude Code's hook events are documented in the [hooks reference](https://code.claude.com/docs/en/hooks); a `PreToolUse` hook can block a call.

## Gotchas & Caveats

- Settle definitions before modelling. The talk's example is whether a hot dog counts as a sandwich.
- Hook events change between releases, which the speaker also warns about.
- The talk is conceptual: it names the tools without showing a working pipeline.
- The speaker's ontology explorer tool is his own project.

## More General Agent news

 [▶ Building a proactive agent: seed its memory, learn from edits and outcomes, and protect attention 2026-12-01](https://openclawdatabase.com/news/videos/2026-12-01-proactive-agents-memory-dreaming-feedback-loop-attention-langchain/)
 [▶ When two MCP connectors both answer: evals on every commit, from Netflix's internal agent rollout 2026-12-01](https://openclawdatabase.com/news/videos/2026-12-01-netflix-mcp-connector-collisions-eval-suite-ci-three-judges/)
 [▶ One Claude does the job, a second plays a picky client: what 100 freelance briefs showed 2026-11-29](https://openclawdatabase.com/news/videos/2026-11-29-claude-100-freelance-jobs-second-claude-picky-client-verifier/)
 [▶ Amp's agent-first habits: tiny deploys the agent watches, shadow systems and a full bug loop 2026-11-29](https://openclawdatabase.com/news/videos/2026-11-29-amp-quinn-slack-21-people-agent-first-bug-loop-shadow-systems/)
 [▶ A self-updating LLM wiki for your agent: raw and wiki folders, CLAUDE.md rules, and a refresh step 2026-11-28](https://openclawdatabase.com/news/videos/2026-11-28-self-updating-llm-wiki-claude-md-topic-yaml-refresh-raw-folder/)
 [▶ 1,000 Claude agents with only Git and a SQL database, and why agent memory needs "dreaming" 2026-11-28](https://openclawdatabase.com/news/videos/2026-11-28-lance-martin-1000-claude-agents-git-sql-coordination-memory-dreaming/)

[See all General Agent news →](https://openclawdatabase.com/news/agents/)

## Go deeper: General Agent guides

Hands-on guides to put this into practice:

 [🧭 Start Here: Before You Install](https://openclawdatabase.com/start/)

 [🧩 Real-World Use Cases](https://openclawdatabase.com/use-cases/)

 [🔐 Agent Security Center](https://openclawdatabase.com/security/)

 [📖 Agent Glossary](https://openclawdatabase.com/glossary/)

 [🧭 Compare Agents Which agent fits your use case — side-by-side.](https://openclawdatabase.com/compare/)

 [⌨️ Command Reference Every CLI command & flag across platforms.](https://openclawdatabase.com/commands/)
