Solution Architecture2 January 20278 min read

Ontology Before Autonomy — Part 6 of 10

Ontology is a guardrail for agent loops

An agent loop that does not know what it is acting on will retry, drift or reach for the wrong tool. Part 6 of Ontology Before Autonomy places an ontology mapping step between language and action, shows how it limits what an agent may propose, and maps seven loop risks to the check that controls each one.

#AI Agents#Ontology#AI Governance#Guardrails#Solution Architecture

Consider an illustrative civil-registration counter where an agent helps an official handle requests in several languages. A person says, through the interpretation route, that they need to change the date for their child's registration. The agent reads "change the date" and "registration" and reaches for the tool that updates an application record. The tool refuses, because the application is already in review. The agent rephrases its call and tries again. Then it tries a different tool. After six attempts it tells the official that the date has been changed. Nothing was changed. What the person wanted was a different appointment.

Every step in that loop was plausible. The agent did not know that an appointment and an application are different objects, that an application in review cannot be edited from the counter, or that "change the date" is ambiguous until something tells it which object the date belongs to.

An ontology is a guardrail for agent loops when every proposed action is first mapped to a named entity, its current state and the role asking, and only the actions permitted for that combination are allowed to reach a tool.

Where loops go wrong

The AI agent loop sets out the general failures: a loop that never stops, the wrong tool, stale context and no record. Each of those has a generic fix, such as step limits, fewer tools, argument validation and tracing. Those fixes are necessary. They do not answer a more basic question, which is what the agent thinks it is acting on.

An agent without that answer fails in particular ways. It retries an action that can never succeed because the object is in the wrong state. It drifts from the person's goal to a neighbouring goal that uses similar words. It selects a tool whose description matches the sentence rather than the service object. It states a result with confidence because nothing in the loop checked that the result exists.

Part 5 argued that rules must be executable and testable rather than written into a prompt, and named four checks a loop must make: state, authority, cost and completion. This part shows where those checks run inside the loop, and adds the step that has to come before them: deciding what kind of thing the agent is acting on and how it relates to everything else in play.

The guardrail pattern

Ontology as a guardrail for an agent loop. A user statement passes through language processing, then an ontology mapping step that names the entity, its state and its relationships, then a policy and authority check for that state and role. If the action is permitted, the agent executes or explains. If the mapping is uncertain, the agent clarifies with the person and maps again. If the action is not permitted, or the ontology cannot represent the situation, the case is escalated to an official or interpreter. The mapping step writes a record of entities, states, unresolved items, permitted actions and any refusal reason. Step, time and cost limits are enforced outside the model.PERSONUserstatementLANGUAGERecognise andtranslateMEANINGOntology mapping:entity, state, linkAUTHORITYAllowed for thisstate and role?DECISIONPermittedaction?MAPPING RECORDEntities, states, unresolved,permitted actions, reasonsyesExecuteor explainuncertainClarify withthe personask, then map againno, orcannot representRefuse with a reason and escalate to an official or interpreterOutside the model: step, time and cost limits per journey, and every refusal recorded with its reasonThe ontology narrows what may be proposed. It does not make the mapping correct, so test the mapping too.
The agent's choice of tool is limited before it is made. Ambiguity leads to a question, a forbidden action leads to a refusal with a reason, and a situation the ontology cannot represent leads to a person. CloudNala analysis.

The pattern has five steps, and the third is the one most designs leave out.

  1. User statement. What the person said, in their language.
  2. Language processing. Recognition, translation and glossary handling, as Part 2 described. The output is text with a confidence signal, not a meaning.
  3. Ontology mapping. The text is mapped to named entities (this is an Appointment, linked to a Service Case, linked to an Application), each with its current state and the relationships that matter for the next step. Anything the mapping cannot resolve is marked as unresolved, not guessed.
  4. Policy and authority check. Given the mapped entities, their states and the role of whoever is asking, which actions are permitted? This is a lookup against rules that live outside the model.
  5. Permitted action? If yes, the agent may execute or explain. If no, or if the mapping is uncertain, the agent must clarify with the person or escalate to a human.

The important property is that the agent's choice of tool is limited before it is made. In the counter example, the mapping step would have found two candidate objects for "the date": the appointment and the application. That is an unresolved mapping, so the only permitted next action is a clarifying question. Had the person confirmed the appointment, the check would have allowed a rebooking tool and nothing else. The update-application tool would never have been offered.

What the mapping step checks

In plain terms, the ontology gives the loop four things to check before any tool call.

  • Type. What kind of thing is this? An application, an appointment, a supporting document, a language session.
  • State. Which state is it in, from a controlled set? An application that is submitted, awaiting documents, in review or closed.
  • Relationship. How is it connected to the other objects in play? This appointment belongs to this service case, which concerns this application.
  • Permitted actions. Which actions are allowed for this type, in this state, for this role? An official may move an appointment; the agent may propose a new slot; nobody at the counter may edit an application in review.

None of this needs a graph database. A table of entity types, a list of valid states and transitions, and a permission table keyed on type, state and role will do for a first version, as Part 8 explains. Where the ontology is held in RDF, the W3C's SHACL (a Recommendation of 20 July 2017, accessed 24 November 2026) is "a language for validating RDF graphs against a set of conditions", and its validation report states whether data conforms and lists each failing result. The same checks can live in ordinary validation code. What matters is that they run outside the model and return a definite answer.

The output of this step is a short, structured record: the entities found, their states, anything unresolved, the permitted actions and the reason for any refusal. That record is what the loop acts on, and it is what a reviewer reads later.

Seven loop risks and the check that controls each

The decision tool for this part is the table below. For each risk, it names the check that the ontology makes possible and what the loop must do when the check fails. Use it to review an agent design before tools are connected.

RiskOntology-backed checkWhen the check fails
Infinite loopsIs the target action valid for the entity's current state? If not, a retry cannot succeedStop retrying; explain the state or escalate
Goal driftDoes each proposed step act on the entity the person confirmed at the start?Return to the confirmed goal or ask again
Unauthorised actionsIs this action permitted for this type, state and role?Refuse and record the refusal reason
Wrong tool selectionIs the tool registered for this entity type and action?Remove the tool from the candidate list
Unsupported certaintyIs every entity in the answer resolved and every state read from a source?Say what is unresolved; ask or escalate
Unbounded costIs the step, time and cost budget for this journey still open?Stop and hand over with the record so far
Silent changes to official recordsDoes the action write to a system of record, and is the required approval present?Propose the change for human approval instead

Two notes on the table. First, the cost row is not really an ontology check. Step, time and cost limits must be enforced by the harness regardless of meaning, as Preventing expensive and destructive tool calls sets out. It sits in the table because a loop that knows which journey it is in can carry a budget per journey rather than one global ceiling. Second, the last row links to the record boundary in Part 10: a proposal is not a record.

What the ontology cannot do

An ontology narrows what an agent may propose. It does not make the agent right.

  • The mapping can be wrong. A model still performs the extraction from text to entities, and it can attach a statement to the wrong object. The guardrail limits the damage, because a wrong mapping usually leads to a refused action or a clarifying question rather than a write. It does not remove the error.
  • It does not eliminate hallucination. A model can still produce fluent, unsupported text inside an explanation. Retrieval, evaluation and human review still apply, as Part 3 and Build the evaluation system before the agent explain.
  • It is only as good as its coverage. A situation the ontology cannot represent must route to a human, not to the nearest matching entity. "Cannot represent this safely" should be an explicit outcome of the mapping step.
  • It does not replace the other control rings. The mapping step sits in the agent harness. The gateway, the business workflow and independent assurance still have their own jobs, as Where should AI guardrails live? sets out.

Test the guardrail directly. Write cases where the statement is ambiguous between two entities, where the entity is in a state that forbids the obvious action, where the role lacks authority, and where the situation is outside the ontology. Each case should end in a clarification, a refusal or an escalation, and each refusal should carry a reason a person can read.

What this means for NalaTolika

NalaTolika is a CloudNala concept and reference architecture for governed language interpretation. It has no customers, deployments, pilots, data or results. In its reference flow, the ontology mapping step sits between translation and policy: the translated text is never sent straight to a tool. A statement that maps cleanly to a permitted explanation can be answered; a statement that maps to a decision belongs to the official; and a statement that cannot be mapped safely goes to clarification or a human interpreter. The companion series Train, Tune or Orchestrate? covers the language capability under the mapping step. This series covers the meaning and authority above it.

How CloudNala can help

CloudNala reviews agent loops before tools are connected. We trace each proposed action back to the entity, state and role it depends on, write the permission table and the refusal reasons with your service owner, build test cases for ambiguity, wrong state, missing authority and out-of-scope situations, and show which risks in the table above your current design leaves open.

Next in the series: The ontology must include humans. Previous: Part 5, Rules stop plausible errors becoming actions. All parts are on the series page.

Sources and limits: this article is CloudNala analysis. The counter scenario is illustrative and does not describe any real service or organisation. The SHACL description comes from the W3C Recommendation of 20 July 2017, accessed on 24 November 2026; it is one way to express validation, not a requirement. NalaTolika is a concept with no deployments. An ontology reduces some kinds of error; it does not eliminate hallucination.


Work with CloudNala

CloudNala helps organisations move from technology ambition to practical execution across cloud, AI, data, platform engineering and digital services.

Whether you are exploring AI, modernising your cloud environment, building a public-sector digital service, or turning an idea into a working MVP, we can help you shape the roadmap and deliver the next step.

Book an Ontology and Agent Governance Assessment or write to us at consult@cloudnala.co.za

Found this useful?

Share