cd /news/artificial-intelligence/two-net-revenues-one-agent-building-… · home › topics › artificial-intelligence › article
[ARTICLE · art-173106] src=pub.towardsai.net ↗ pub= topic=artificial-intelligence verified=true sentiment=· neutral

Two Net Revenues, One Agent: Building a Governed Business Ontology in Snowflake Before the Native…

Snowflake has announced Business Ontology, a governance layer for enterprise metric definitions, but the feature is in private preview and was not available in the author's account, so the author rebuilt the same governance model from generally available Snowflake primitives and deployed it end to end. The build treats a governed ontology as an authorization problem first, using a single row access policy (CORE.RAP_ONTOLOGY_OBJECT) over concepts, versions, edges, representations, drift and audit rows, and a probe procedure that showed role functions inside an EXECUTE AS OWNER procedure see the owner while CURRENT_USER() returns the caller. The author's example is two conflicting definitions of net revenue — Finance's recognized revenue after refunds and discounts versus Sales' bookings net of discounts at signing — which an agent pointed at both semantic views cannot choose between.

recommendation

Do not gate agent-visible data with IS_ROLE_IN_SESSION inside owner's-rights procedures; probe the behavior first, then resolve permissions by walking SHOW GRANTS OF ROLE from the domain's privilege role to the calling user.

more in playbook: Securing agents and AI tools
by read7 min views2 publishedNov 20, 2026

Ask an AI agent “what was net revenue last quarter?” and it will happily give you a number. The problem is that most enterprises have at least two correct answers. Finance means recognized revenue after refunds and discounts. Sales means bookings net of discounts at signing. Semantic views fix how a number is computed, but they don’t record which meaning the business stands behind, who approved it, or who is allowed to see it.

Snowflake has announced Business Ontology for exactly this gap. It is in private preview, and it wasn’t available in the account I was working in. So I built the same governance model from generally available primitives and deployed it end to end.

The thesis: a governed ontology is an authorization problem first and a modeling problem second. If you get the trust boundaries wrong, the agent will quote definitions to people who should never see them.

A semantic view is authoritative for a calculation. It is not an approval workflow, and it doesn’t model the relationship between two teams’ definitions. In the demo estate I built, both of these exist and both are right:

Finance.Net RevenueSales.Net RevenueDefinitionRecognized revenue after refunds and discountsBookings net of discounts at signingTime policyRecognition dateSigning dateExclusionsIntercompany invoices, test accountsNoneComputed byFINANCE_REVENUE_SV → INVOICES.NET_REVENUESALES_BOOKINGS_SV → BOOKINGS.NET_REVENUEApproverFinance stewardSales steward

An agent pointed directly at both semantic views has two metrics with the same name and no basis for choosing between them.

Three decisions shape everything else:

One policy covers concepts, versions, edges, representations, drift and audit rows. It takes (domain_id, status, author):

ALTER ROW ACCESS POLICY CORE.RAP_ONTOLOGY_OBJECT SET BODY ->  IS_ROLE_IN_SESSION('ONTOLOGY_ADMIN')  OR (    -- every strict ancestor domain must be navigable (USAGE)    (SELECT COUNT(*) FROM CORE.DOMAIN_ANCESTOR a      WHERE a.domain_id = p_domain_id AND a.depth > 0)    =    (SELECT COUNT(DISTINCT a.ancestor_id) FROM CORE.DOMAIN_ANCESTOR a       JOIN CORE.DOMAIN_ACCESS x ON x.domain_id = a.ancestor_id AND x.privilege = 'USAGE'      WHERE a.domain_id = p_domain_id AND a.depth > 0        AND IS_ROLE_IN_SESSION(x.role_name))    AND EXISTS (      SELECT 1 FROM CORE.DOMAIN_ACCESS x       WHERE x.domain_id = p_domain_id AND IS_ROLE_IN_SESSION(x.role_name)         AND (x.privilege = 'MODIFY'              OR (x.privilege = 'READ'    AND p_status IN ('APPROVED','SUPERSEDED'))              OR (x.privilege = 'SUGGEST' AND p_author = CURRENT_USER()))));

What matters here:

Consumers get SELECT on API secure views and nothing in CORE. An integration test asserts that even a steward can't query CORE.CONCEPT directly.

My first design checked steward rights inside owner’s-rights procedures with IS_ROLE_IN_SESSION. Before writing any workflow code, I deployed a probe procedure and called it from a restricted role with secondary roles off:

{"role": "ONTOLOGY_ADMIN", "user": "SATISH", "in_probe": false}

Inside an EXECUTE AS OWNER procedure, role functions see the owner, but CURRENT_USER() is the caller. Any steward check written with IS_ROLE_IN_SESSION would silently evaluate the service role's privileges. Approving would either always succeed or always fail, depending on what the service role holds.

So authorization walks the grant graph upward from the domain’s privilege role until it reaches the calling user:

def user_holds_role(session, role, user):    frontier, visited = [role.upper()], set()    while frontier:        r = frontier.pop()        if r in visited:            continue        visited.add(r)        for g in session.sql(f'SHOW GRANTS OF ROLE "{r}"').collect():            g = g.as_dict()            if g["granted_to"] == "USER" and g["grantee_name"].upper() == user.upper():                return True            if g["granted_to"] == "ROLE":                frontier.append(g["grantee_name"].upper())    return False

The consequences, which I’d rather state than hide:

Every write procedure validates, writes and records its AUDIT_EVENT in one transaction. Callers have no DML at all.

I enforced only rules that change how a concept is interpreted. Each one is a unit test:

The APPLIES_TO rule is what lets the agent say "periods by recognition date" without the policy being baked into its prompt.

The agent has two ontology tools, search_business_ontology and get_concept_details. Both are caller's-rights SQL procedures over the secure views:

tool_resources:  search_business_ontology:    type: procedure    identifier: ONTOLOGY_DB.API.SEARCH_CONCEPTS    execution_environment: {type: warehouse, warehouse: COMPUTE_WH}

A Cortex Search service would have ranked better. My reasoning (a design assumption, not something I benchmarked) was that a service built over the concept table indexes it with its owner’s view of the data. Role filtering would then become a filter the agent chooses to apply, rather than a policy the platform enforces. A caller’s-rights procedure keeps the row access policy in the path.

The search returns policies, edges, implementing metrics and an ambiguous_terms list. That list is the agent's cue to ask a clarifying question instead of guessing.

I wrote 21 integration tests that run as six personas: author, Finance steward, Sales steward, Finance analyst, an exec with both domains, and an outsider. The checks include:

All 21 pass, along with 20 unit tests and 2 agent-behavior tests.

Lessons from making them pass. None of these are in a tutorial.

One more environment constraint is worth stating plainly. My Snowsight sandbox routes connections through a proxy that only accepts OAuth, so the key-pair persona users couldn’t log in. The harness has a fallback mode: my own user holds exactly one persona role at a time, with secondary roles off. Visibility and privilege checks remain fully real. Separation of duties can’t be tested positively with one human, so dev turns it off, and a dedicated test proves it blocks self-approval when on. CI uses separate users.

As a role with both Finance and Sales READ:

User: What was net revenue last quarter? Agent: “Net revenue” has two approved definitions… Finance.Net Revenue… Sales.Net Revenue… Which one should I use? User: Finance. Agent: …$3,767,662.13 … from 784 reportable invoices. Policies applied: Finance.Revenue Recognition Policy. Exclusions: intercompany invoices, test accounts. Number: GOVERNED (FINANCE_REVENUE_SV.INVOICES.NET_REVENUE).

An independent SUM(invoice) - SUM(refund) - SUM(discount) over the reportable view for July–September 2026 returned the same $3,767,662.13 across 784 invoices. As the Finance-only analyst, the agent never asked a question. It couldn't see the Sales definition, so for that user there was no ambiguity. The demo data is synthetic, so treat this as proof of behavior, not a business result.

Deploy with bash deploy.sh, which unit-tests, deploys, seeds the demo and smoke-tests in one go. Then run these. The full list is in docs/TESTING.md.

1. Ambiguity is per user. Ask the agent in Snowsight (AI & ML → Agents → ONTOLOGY_AGENT) “What was net revenue last quarter?” under two roles:

GRANT ROLE ONT_DEMO_EXEC_ROLE        TO USER <your_user>;  -- Finance + SalesGRANT ROLE ONT_DEMO_FIN_ANALYST_ROLE TO USER <your_user>;  -- Finance only

The exec is asked which meaning they want. The analyst gets the Finance answer directly. Gotcha: with DEFAULT_SECONDARY_ROLES = ('ALL'), every role you hold applies in the session, and you'll see the admin view every time. Turn secondary roles off while testing.

2. The agent sees what the caller sees. Run the agent’s own tool as each role:

CALL ONTOLOGY_DB.API.SEARCH_CONCEPTS('net revenue');

As the outsider role the result is empty, not an error. For roles without access, concepts behave as if they don’t exist.

3. Pending edits don’t leak. As the author, call PROPOSE_EDIT on Finance.Net Revenue. Readers still get VERSION_NO = 1, HAS_PENDING_EDIT = TRUE, and the agent still cites v1. Approve the edit as the steward, and the next answer cites v2. API.V_AUDIT shows both actions with the real user.

4. Drift surfaces instead of healing. Re-create the semantic view with a different NET_REVENUE expression and run CORE.VALIDATE_REPRESENTATIONS(). The steward sees FORMULA_CHANGED in API.V_DRIFT_OPEN, and nothing changes until they call ACKNOWLEDGE_DRIFT(..., 'ACCEPT').

If any of these gives you the “admin view” when it shouldn’t, check your active and secondary roles before suspecting the code. That’s also why the test harness runs every persona with USE SECONDARY ROLES NONE.

Use it when agents are already answering business questions, you have competing definitions, and you can’t wait for native Business Ontology. Avoid it if native Business Ontology is enabled in your account. Use the product, and treat this design as a description of the behavior you should demand from it. Plan to migrate when the native feature reaches your account. The model maps one to one (domains, the same four privilege names, typed edges, representations), and the export procedure exists for that move.

The complete implementation, including Snowflake SQL scripts and supporting code, is available on GitHub

Found this useful? Clap 👏, share, and follow Snowflake Chronicles for practical Snowflake architecture insights. Let’s also connect on ** LinkedIn**.

Reuse & Attribution: Feel free to share or adapt with proper credit and a link to the original post. Shared for educational purposes — please test and validate before production use. Views are my own and do not represent any current or former employer

Two Net Revenues, One Agent: Building a Governed Business Ontology in Snowflake Before the Native… was originally published in Towards AI on Medium, where people are continuing the conversation by highlighting and responding to this story.

── more in #artificial-intelligence 4 stories · sorted by recency
── more on @snowflake 3 stories trending now
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain — perfect for shipping the agent you just read about.

$git push zahid main
→ Live at https://your-agent.zahid.host ✓
Get free account → Pricing
from €0/mo · no card required
LIVE [news/two-net-revenues-one…] indexed:0 read:7min 2026-11-20 · —