Codú
Ranknod6 min read

Building Safer AI Actions Into Web Apps

Adding AI to a web app is easy when the model only returns text.

A user submits a prompt, the model generates a response, and the UI displays it:

User input

→ Model

→ Generated response

→ UI

The architecture changes when the model is allowed to change something.

Maybe it can update a page title, create a database record, trigger a deployment, or publish content. At that point, a useful AI response is no longer enough. Your application has to decide whether the proposed action should actually happen.

A practical rule is:

Let the AI propose the change. Let your application own execution.

Treat AI output as a proposal

Suppose your app lets an AI assistant update a page.

Instead of letting the model call your database directly, ask it for a structured proposal:

{

"action": "update_page",

"pageId": "142",

"changes": {

"title": "Safer AI Actions"

}

}

Now the model has expressed intent, but nothing has changed yet.

That gives your backend something predictable to inspect before any side effect occurs.

The application can ask:

  • Does page 142 exist?

  • Is update_page a supported action?

  • Is the title field editable?

  • Is the proposed value valid?

  • Is the current user allowed to edit this page?

  • Does this particular change require approval?

These are ordinary application checks. AI does not replace them.

Keep authorization in your application

Your web app already has a source of truth for permissions.

It knows who the user is, what role they have, which resources they can access, and which operations they are allowed to perform.

Keep those rules in charge when AI enters the workflow.

If a user cannot manually delete a project, an AI acting for that user should not quietly gain permission to delete it just because the model selected a tool.

A useful principle is:

AI should inherit constraints, not bypass them.

That also means authentication and authorization should be evaluated outside the model. The model can suggest update_page; application code decides whether that request is permitted.

Make review a real workflow state

Some AI-generated changes are low risk. Others deserve a person in the loop.

If approval matters, represent it as application state instead of relying on a prompt such as “ask the user before changing anything.”

For example:

PROPOSED

↓

VALIDATED

↓

AWAITING_APPROVAL

↓

APPROVED

↓

EXECUTED

The frontend can reflect those states directly:

AI change proposed

Validation passed

Waiting for your approval

Change applied

That is clearer than a spinner followed by a surprise update.

It also gives your backend explicit transitions that can be queried, tested, and audited.

Show the user what will actually change

An approval screen should provide enough context for a person to make a useful decision.

Avoid a vague prompt like:

Approve this AI action?

For a page-title update, show the difference:

Current title:

AI Workflows

Proposed title:

Building Reliable AI Workflows

[Approve] [Reject]

For larger changes, a diff view is more useful.

The important part is that approval applies to a specific proposed change. If the underlying page changes before execution, the application should revalidate the current state rather than blindly executing an approval that no longer matches reality.

Make retries safe

Now imagine the approved update reaches your execution endpoint.

The page changes successfully, but the network response is lost. Your app sees a timeout and retries the request.

Without protection, the same side effect can happen twice.

A unique operation ID gives the backend a stable way to recognize the operation:

{

"operationId": "op_7281",

"action": "update_page",

"pageId": "142"

}

Before executing, the backend checks whether op_7281 is already running or completed.

The operation ID should come from, or be validated by, trusted application or orchestration code. It should not become trustworthy simply because a model returned a string that looks like an ID.

The model can help decide what should happen. Your application should remember what has already happened.

Keep an audit trail

When an AI-generated action changes real application state, debugging becomes easier if the workflow leaves a useful record.

For important actions, consider storing:

  • who requested the operation;

  • what the AI proposed;

  • which validation rules ran;

  • the authorization result;

  • whether approval was required;

  • who approved it;

  • the operation ID;

  • what the executor did;

  • whether execution succeeded.

You do not need an enormous event log for every tiny feature. The amount of auditing should match the consequence of the action.

But when someone asks, “Why did this page change?”, the answer should be easier to find than “the model called a tool.”

Put the boundary in the architecture

The full flow can stay simple:

Browser

↓

Application API

↓

AI service

↓

Structured proposal

↓

Validation

↓

Authorization

↓

Approval if required

↓

Executor

↓

Database / External API

The important detail is the gap between generation and execution.

The AI service does not receive unlimited authority over your database or external APIs. It proposes a change, while normal application code decides whether that change is valid and permitted.

That boundary also gives you places to add retries, state checks, approval, idempotency, and auditing without pushing those responsibilities into prompts.

Add autonomy gradually

You do not need to jump directly from manual workflows to full automation.

A sensible starting point is:

AI suggests

→ human approves

→ system executes

After you observe how the workflow behaves, you can decide whether some categories are safe enough to run automatically:

low-risk action

→ automatic execution

unusual or higher-risk action

→ review

The point is not to maximize the number of actions an AI can perform. It is to give each action the right level of control.

Ranknod is being built around a related governed-workflow approach for agencies and growth teams, but the same web-development principle applies much more broadly: generation, authorization, and execution are different responsibilities.

Keep them separate.

Practical takeaways

When adding AI actions to a web app:

  • make the model return structured proposals;

  • validate them with normal backend code;

  • enforce the user's existing permissions;

  • represent approval as workflow state;

  • show users the exact proposed change;

  • revalidate important state before execution;

  • use trusted operation IDs for safe retries;

  • keep an audit trail for meaningful actions;

  • give the executor a narrow, predictable job.

A useful next step is to pick one AI-powered action in your app and draw the path from model output to the final side effect. If the model can jump directly to the database or external API, that is probably the first boundary worth adding.

How are you separating AI-generated decisions from execution in your web apps?

Ranknod@ranknodofficial

Governed AI operating system for agencies and growth teams. Strategy → execution → verification → measurement → learning.

Discussion 0

Loading

Got something to say?

or to join the conversation.

Learn to build with AI and grow with people doing the same — it's free.