Zero Labs
Industry News / AI

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

Source · Towards AI By Satish Kumar

From the publisher’s feed, collected in the ZeroLabs newsroom.

Two Net Revenues, One Agent: Building a Governed Business Ontology in Snowflake Before the Native Feature ShipsWhat I learned building steward-approved, role-filtered business meaning for Cortex Agents out of row access policies, owner’s-rights procedures and semantic views, including the four security assumptions that turned out to be wrong.OpeningAsk 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.TL;DRBusiness meaning lives in Snowflake tables. Reads are enforced by row access policies, and writes go only through owner’s-rights procedures.Inside an owner’s-rights procedure, CURRENT_USER() is the caller, but role checks evaluate against the owner. Authorization has to walk the caller's grant graph explicitly.Ontology retrieval for the agent is a caller’s-rights procedure, so the agent only sees what the person asking can see.Representations (concept → semantic-view metric) are snapshotted, and a task detects drift. Only a steward can re-baseline.The agent asked which Net Revenue the user meant, then returned $3,767,662.13 for Q3 2026, which matched an independent SQL query exactly.Code: the business-ontology/ repo (deploy scripts, Python procedure package, tests, runbook).The problem: semantic views answer “how”, not “which” or “who”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 stewardAn agent pointed directly at both semantic views has two metrics with the same name and no basis for choosing between them.Design goalsApproved meaning only. Drafts never reach the agent.Domain-qualified identity. Finance.Net Revenue and Sales.Net Revenue coexist, each with its own owner.Per-domain privileges (USAGE / READ / SUGGEST / MODIFY), with no inheritance to child domains and navigation of the parent path required.Approval belongs to the steward, not the account admin.Links to real assets, validated on creation and re-checked on a schedule.No component outside Snowflake.The architectureThree decisions shape everything else:Identity is split from content. CONCEPT holds identity plus pointers to the current and pending versions. CONCEPT_VERSION is append-only. That makes "agents keep using v1 while v2 waits for approval" a pointer, not a locking scheme.Reads and writes use different enforcement mechanisms, because they have different trust boundaries.The agent’s ontology tool is a procedure, not a search service. More on that below.Reads: row access policies evaluated as the callerOne 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:IS_ROLE_IN_SESSION(x.role_name) takes the role name from a mapping table. Before relying on it, I checked that a policy can do this.Domain privilege roles are generated per domain and nested MODIFY ⊃ SUGGEST ⊃ READ ⊃ USAGE. Checking the lower role covers holders of the higher ones.The closure table (DOMAIN_ANCESTOR) turns "can navigate Finance to reach Finance.EMEA" into a count comparison instead of recursion inside a policy.Audit and drift rows reuse the same policy. Their “status” column never equals APPROVED, so only stewards see them.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.Writes: the assumption that broke firstMy 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 FalseThe consequences, which I’d rather state than hide:Authorization is based on roles granted to the user, not the role currently active. “Steward = the person holding the steward role” is the semantics most governance teams want, but it differs from normal Snowflake behavior.The service role needs MANAGE GRANTS to see grants of business roles it doesn't own. That is a significant privilege, so put it in front of your security team.The account admin is not an approver unless it is granted a domain’s MODIFY role. A separate REQUIRE_DISTINCT_APPROVER setting blocks self-approval.Every write procedure validates, writes and records its AUDIT_EVENT in one transaction. Callers have no DML at all.The model rules that earn their keepI enforced only rules that change how a concept is interpreted. Each one is a unit test:Only METRIC concepts can carry a formula, exclusions or formula provenance.CUSTOM edges require an UPPER_SNAKE label, and no other edge type may have one.EQUIVALENT_TO is cross-domain only. A same-domain duplicate gets merged, not linked.APPLIES_TO must start at a POLICY. IS_A, HAS_PART and DERIVES are acyclic.A representation must point at an asset the service role can actually describe. BI_ASSET can't IMPLEMENT.The APPLIES_TO rule is what lets the agent say "periods by recognition date" without the policy being baked into its prompt.Retrieval: why the agent’s ontology tool is a procedureThe 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.Testing it with real personas, and what that taught meI 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:The Finance analyst sees exactly {Finance}, and not Finance.EMEA, because there is no inheritance.Drafts are visible only to their author and the steward.A pending edit leaves readers on v1. After approval, history shows SUPERSEDED, APPROVED.The outsider gets zero search results, so concepts behave as if they don’t exist.Export is role-filtered.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.The resultAs 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.Production realityWhat fails: the drift task (it suspends after three failures), assets the service role can’t see (reported as missing), and stale review queues.What to monitor: a single OPS.V_HEALTH row with open drift, stale validations, reviews older than seven days, and metrics with no implementation. Optionally add an email alert on new drift.Cost: small. Lookups are tiny tables. The main compute is the scheduled validation (one DESCRIBE per representation) and agent tool calls on a warehouse. I didn't measure credits.Scale limits: search is lexical. Grant-graph walks cost one SHOW GRANTS per role visited, cached per call. Very deep role hierarchies will make writes slower, though reads aren't affected.Recovery: versions are append-only and every change is audited, so Time Travel plus a clone reconstructs the approved ontology at any point in time.Try it yourself: four tests worth runningDeploy 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 ; -- Finance + SalesGRANT ROLE ONT_DEMO_FIN_ANALYST_ROLE TO USER ; -- Finance onlyThe 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.Trade-offsUse 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.Architect’s takeawaysSeparate meaning, computation and access. The ontology says what a term means, the semantic view computes the number, and the policy decides who sees either.Test your security assumptions with a probe before writing workflow code. The owner’s-rights role behavior would have invalidated every approval check.Retrieval must inherit the caller’s permissions. If your agent’s context layer runs as an owner, your governance is only a convention.Drift is a governance event, not a sync job. Never auto-heal a baseline.Ambiguity is per user. The same question is ambiguous for an exec and unambiguous for a Finance analyst, and the system should behave differently for each.What changes architecturally isn’t that an agent can look up a glossary. It’s that business meaning becomes a governed object with the same trust boundaries as the data itself, so the clarifying question a new hire asks a colleague can now be answered by the platform.Youtube Demo:https://medium.com/media/aa55d1aa2704c4182a8858559bb38d7d/hrefThe complete implementation, including Snowflake SQL scripts and supporting code, is available on GitHubFound 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 employerTwo 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.