Building CoWork Agents That Understand Business Context
Semantic views serve as critical business logic contracts, requiring unnaturally explicit metric definitions to prevent LLM ambiguity and ensure consistent agent behavior. The distinction between Cortex Analyst (structured SQL) and Cortex Search (unstructured retrieval) must be enforced via explicit orchestration instructions to prevent misrouting of queries. Verified queries (curated question-SQL pairs) offer the highest return on investment, boosting accuracy from approximately 60% to 92% by b
Analysis
TL;DR
- Semantic views serve as critical business logic contracts, requiring unnaturally explicit metric definitions to prevent LLM ambiguity and ensure consistent agent behavior.
- The distinction between Cortex Analyst (structured SQL) and Cortex Search (unstructured retrieval) must be enforced via explicit orchestration instructions to prevent misrouting of queries.
- Verified queries (curated question-SQL pairs) offer the highest return on investment, boosting accuracy from approximately 60% to 92% by bypassing generative SQL errors for known complex questions.
- Implementation details matter significantly, such as the silent ignoring of
data_typeon metrics and the shift from delegating tosystem_execute_sqlfor direct SQL generation.
Why It Matters
This article highlights a critical shift in AI agent development: success depends less on prompt engineering and more on the rigorous definition of business semantics and data governance. For practitioners, it underscores that building reliable enterprise agents requires treating data definitions as code, with strict contracts to handle organizational nuance. It provides actionable guidance on avoiding common pitfalls in tool routing and metric definition that often lead to "dangerous" rather than just inaccurate outputs.
Technical Details
- Semantic View Structure: Defined via YAML, containing tables, columns, metrics (with
name,description,expr,synonyms), dimensions, and relationships. Metrics infer data types from expressions;data_typeis only valid for dimensions/facts. - Metric Definition Strategy: Simple aggregations like
SUM(amount)are insufficient due to business ambiguity. Effective definitions include explicit exclusion criteria (e.g., "excludes trial credits") and map multiple synonyms to a single canonical metric. - Orchestration Logic: Agents use two tools:
cortex_analyst_text_to_sqlfor structured data andcortex_searchfor unstructured data. Routing is controlled via aninstructionsblock specifying operational constraints for policy vs. numerical queries. - Verified Queries: Stored within the semantic view, these are curated question-SQL pairs. When user intent matches a verified query, the agent executes the pre-written SQL instead of generating new code, significantly improving accuracy for complex logic.
- Access Control: Semantic view access utilizes
GRANT SELECTrather thanGRANT USAGEon underlying tables, simplifying permission management for end-users.
Industry Insight
- Invest in Data Semantics First: Organizations should invert their current resource allocation, spending the majority of effort on defining precise, unambiguous business logic in semantic views rather than on agent orchestration or prompt tuning.
- Standardize Metric Definitions: Establish a centralized, YAML-based standard for metric definitions that includes explicit business rules and synonyms. This reduces the cognitive load on LLMs and ensures consistency across different queries and users.
- Prioritize Verified Queries for Complex Logic: Implement verified queries early in the deployment lifecycle for high-stakes or complex calculations. This serves as a safety net against generative errors and provides immediate, measurable improvements in agent reliability.
Disclaimer: The above content is generated by AI and is for reference only.