Databricks: when to use a custom UC-function agent instead of Genie
Context: a conversational analytics agent over Delta tables (Llama 3.3 70B via LangChain create_agent; tools = Unity Catalog SQL functions called through databricks_langchain.UCFunctionToolkit; served with agents.deploy).
Decision rule that held up: - Custom agent + fixed UC SQL functions: when the metric has subtle join or grain traps and must be computed the same way every time. Example: retail promo lift, where joining causal (product x store x week) without STORE_ID fanned out sales across stores, and LEFT JOIN NULLs had to be COALESCEd into the baseline. The LLM only picks a function and fills typed args; it never writes SQL. Each function's COMMENT doubles as the tool description. - Genie: ad-hoc, open-ended questions where flexibility matters more than one verified metric definition. It generates SQL per question, so correctness can drift between runs. Genie spaces can be constrained with trusted assets (verified example SQL, UC functions).
Costs of the custom route: only answers what the tools cover, and transform-on-read means each call joins large tables (10-30 s per answer here). Precompute an aggregate table to cut latency.