# Govern AI agent responses with OpenAI and Postgres: n8n workflow

> Started by another system calling it, and works across Gmail and Postgres. 32 steps, 5 branches: large, and worth reading before you trust it with anything...

Source: https://millionrounds.com/workflow/govern-ai-agent-responses-with-openai-and-postgres (Millionrounds; every figure on the page links to its filing or article)

[Automation library](https://millionrounds.com/workflows) · [Content](https://millionrounds.com/workflows?category=Content#library)

# Govern AI agent responses with OpenAI and Postgres

Started by another system calling it, and works across Gmail and Postgres. 32 steps, 5 branches: large, and worth reading before you trust it with anything live.

Large

[Download free](https://millionrounds.com/login?next=%2Fapp%2Fworkflow%2Fgovern-ai-agent-responses-with-openai-and-postgres)

**32 steps** Large: read it before trusting it with anything live

**5** Branches: places the flow splits

**0** Loops or waits

**2** Services it connects to

## The flow

Starts it 1 Logic 24 Service 7

The steps in the order they run, from what starts it.

- 1 **AgentGuard - Request Entry** Webhook *Starts it*
- 2 **AgentGuard - Request Normalizer** Code *Logic*
- 3 **AgentGuard - Security Gate** Code *Logic*
- 4 **AgentGuard - Security Decision** If *Logic*
- 5 **AgentGuard - Query Embedding** Http Request *Service*
- 6 **AgentGuard - Security Rejection** Code *Logic*
- 7 **AgentGuard - Embedding Normalizer** Code *Logic*
- 8 **AgentGuard - Semantic Retrieval** Postgres *Service*
- 9 **AgentGuard - Grounding Engine** Code *Logic*
- 10 **AgentGuard - Grounding Decision** If *Logic*
- 11 **AgentGuard - Agent Policy & Prompt** Code *Logic*
- 12 **AgentGuard - Grounding Escalation** Code *Logic*
- 13 **AgentGuard - Tool Intent Normalizer** Code *Logic*
- 14 **AgentGuard - Tool Gateway** Code *Logic*
- 15 **AgentGuard - Tool Risk & Permissions** Code *Logic*
- 16 **AgentGuard - Tool Approval Decision** If *Logic*
- 17 **AgentGuard - Controlled Tool Execution** Code *Logic*
- 18 **AgentGuard - Tool Approval Queue** Code *Logic*
- 19 **AgentGuard - Tool Result Validator** Code *Logic*
- 20 **AgentGuard - Agent Runtime** Http Request *Service*
- 21 **AgentGuard - Output Normalizer** Code *Logic*
- 22 **AgentGuard - Verification Engine** Http Request *Service*
- 23 **AgentGuard - Verification Decision** Code *Logic*
- 24 **AgentGuard - Verification Gate** If *Logic*
- 25 **AgentGuard - Cost Controller** Code *Logic*
- 26 **AgentGuard - Repair & Retry** Code *Logic*
- 27 **AgentGuard - Risk Engine** Http Request *Service*
- 28 **AgentGuard - Risk Decision** Code *Logic*
- 29 **AgentGuard - Human Approval Decision** If *Logic*
- 30 **AgentGuard - Observability & Audit** Postgres *Service*
- 31 **AgentGuard - Human Approval Queue** Code *Logic*
- 32 **AgentGuard - Output Delivery** Gmail *Service*

## How it's built

- **Starts on:** Another system calling it
- **Steps:** 32, with 5 branches
- **Size:** Large: read it before trusting it with anything live
- **Connects to:** Gmail, Postgres
- **Model:** None. This is plumbing, not judgement

## Questions

What does it need to run?

An n8n account, plus your own Gmail and Postgres accounts. You connect your own accounts after importing it; none are included.

What starts it?

It starts on another system calling it.

Does it use AI?

No. Every step is fixed logic or a call to a service, so it does the same thing every time.

How long does it take to set up?

Take your time. At 32 steps it is large: read it before trusting it with anything live.

How do I import it?

Copy the workflow, open a new workflow in n8n and paste. The steps appear on the canvas, ready for your own accounts.

**Before you run it**

Nothing here has been tested by us. It is somebody's working automation, read and described from its own steps. Treat the connections it wants as a list of accounts it will touch, and read the 32 steps before you point it at anything that matters.

## Run it in n8n

- **Create your n8n account** Free to start. n8n is where the workflow runs. [Create an n8n account ↗](https://millionrounds.com/n8n)
- **Download the workflow** Free with a Millionrounds account. [Download free](https://millionrounds.com/login?next=%2Fapp%2Fworkflow%2Fgovern-ai-agent-responses-with-openai-and-postgres)
- **Paste it into n8n** Open a new workflow in n8n and paste. Then connect your own accounts.

Stored with the author's traces removed: canvas notes, instance identifiers, saved credential names and any live document they had left behind.

## Connects to

Each opens the other workflows that use it.

[Gmail](https://millionrounds.com/workflows?service=Gmail#library)[Postgres](https://millionrounds.com/workflows?service=Postgres#library)

## Workflows like it

Also content, with the same services where possible, closest in size first.

- [**Automate testing and collect responses with Telegram** 32 steps · Postgres, Telegram](https://millionrounds.com/workflow/automate-testing-and-collect-responses-with-telegram)
- [**Translate RSS news and publish** 31 steps · Discord, Gmail](https://millionrounds.com/workflow/translate-rss-news-and-publish)
- [**AI news research team: 24/7 newsletter automation** 31 steps · calls a model · Gmail, Google Sheets](https://millionrounds.com/workflow/ai-news-research-team-24-7-newsletter-automation)
- [**Detect and email top job matches with RemoteOK and Arbeitnow** 31 steps · calls a model · Gmail, Postgres](https://millionrounds.com/workflow/detect-and-email-top-job-matches-with-remoteok-and-arbeitnow)
- [**Generate & test SQL code with OpenRouter AI and PostgreSQL** 33 steps · calls a model · MySQL, Postgres](https://millionrounds.com/workflow/generate-and-test-sql-code-with-openrouter-ai-and-postgresql)
- [**Generate content strategy reports analyzing Reddit, YouTube & X** 31 steps · calls a model · Gmail, Google Sheets](https://millionrounds.com/workflow/generate-content-strategy-reports-analyzing-reddit-youtube-a)
