Symptom
A function such as main.util.mask_email or main.util.parse_sku was registered in Unity Catalog. It works in the author's notebook, but one of these fails:
- A scheduled job, dashboard or Genie space reports
[UNRESOLVED_ROUTINE] Cannot resolve routine .... - Another user or a service principal gets
PERMISSION_DENIEDon the function. - A view that calls the function works on one warehouse but fails on another.
- A Python UDF fails when it imports a package or calls an external API.
Most of these come down to four causes: the name doesn't resolve, the caller lacks grants, the compute type doesn't support the function, or the Python sandbox lacks a dependency or network access.
Quick map
| Error or behaviour | Likely cause | Fix |
|---|---|---|
UNRESOLVED_ROUTINE in a job but not in the notebook | unqualified name; the job has a different current catalog/schema | use the three-part name catalog.schema.function |
UNRESOLVED_ROUTINE for a function that "exists" | it was a TEMPORARY function or spark.udf.register, which last only for one session | register it in Unity Catalog with CREATE FUNCTION |
PERMISSION_DENIED ... EXECUTE | no EXECUTE on the function | GRANT EXECUTE ON FUNCTION |
PERMISSION_DENIED ... USE SCHEMA / USE CATALOG | the caller can't reach the schema | grant USE CATALOG and USE SCHEMA |
| View with a Python UDF fails on one warehouse | classic SQL warehouse | use a pro or serverless SQL warehouse |
| Python UDF fails on a cluster | runtime too old, or the compute isn't Unity Catalog-enabled | DBR 13.3 LTS or above in standard or dedicated access mode |
ModuleNotFoundError inside the UDF | package not declared in ENVIRONMENT | add it to dependencies |
| Dependency install fails on a serverless SQL warehouse | no outbound internet for isolated workloads | put the wheel in a volume, or enable the networking preview |
| HTTP call from a Python UDF times out | port blocked, or a serverless network policy | only ports 80, 443 and 53 are allowed; check the egress policy |
CREATE OR REPLACE FUNCTION denied | you don't own the function | function owner, or MANAGE, or ownership of the schema/catalog |
Checks
1. Does the function exist where you think it does?
SHOW USER FUNCTIONS IN main.util;
DESCRIBE FUNCTION EXTENDED main.util.mask_email;
DESCRIBE FUNCTION EXTENDED shows the owner, input and return types, the body, and whether it's a SQL or Python function. To search across catalogs, for example when people disagree about which schema holds the function:
SELECT routine_catalog, routine_schema, routine_name,
routine_owner, routine_body, external_language, last_altered
FROM system.information_schema.routines
WHERE routine_name ILIKE '%mask_email%';
If nothing comes back, the function was never registered in Unity Catalog. It was probably a CREATE TEMPORARY FUNCTION or a PySpark spark.udf.register(...) in the author's session. Those exist only in that session, so a job or a warehouse never sees them.
2. Is the job calling the right name?
A notebook usually runs with a current catalog and schema set by the author (USE CATALOG main; USE SCHEMA util;). A job task, a SQL warehouse query or a dashboard dataset usually doesn't. The UNRESOLVED_ROUTINE message prints the search path it tried. If main.util isn't on that path, an unqualified mask_email(email) fails.
Fix it in the code, not in the session:
SELECT main.util.mask_email(email) AS email_masked
FROM main.crm.customers;
Views store the function name as written. If a view was created with an unqualified name, recreate it with the three-part name.
3. Does the caller have the grants?
To run a function, a caller needs all three: USE CATALOG on the catalog, USE SCHEMA on the schema, and EXECUTE on the function.
SHOW GRANTS ON FUNCTION main.util.mask_email;
SELECT grantee, privilege_type, inherited_from
FROM system.information_schema.routine_privileges
WHERE routine_catalog = 'main'
AND routine_schema = 'util'
AND routine_name = 'mask_email';
Grant to groups, not to individuals:
GRANT USE CATALOG ON CATALOG main TO `data-analysts`;
GRANT USE SCHEMA ON SCHEMA main.util TO `data-analysts`;
GRANT EXECUTE ON FUNCTION main.util.mask_email TO `data-analysts`;
-- or every current and future function in the schema
GRANT EXECUTE ON SCHEMA main.util TO `etl-service-principals`;
For jobs, check the Run as identity on the job, not the person who scheduled it. Dashboards and Genie spaces may run as the viewer or as the publisher, depending on how they were shared. The grant has to reach whichever identity actually runs the query.
Warning
If the function's owner leaves, or the owner's account is deactivated, later
CREATE OR REPLACEdeployments fail. Move ownership to a group or a deployment service principal now:
ALTER FUNCTION main.util.mask_email OWNER TO `platform-admins`;
4. Does this compute support the function?
| Compute | SQL UDF | Python UDF |
|---|---|---|
| Serverless notebooks and jobs | yes | yes |
| Pro or serverless SQL warehouse | yes | yes |
| Classic SQL warehouse | yes | no (views that use one fail too) |
| Classic cluster, Unity Catalog-enabled, DBR 13.3 LTS+ | yes | yes |
ENVIRONMENT clause on classic compute | n/a | DBR 16.2+, with limits on environment_version before DBR 18.2 |
Find which warehouse type a failing dashboard uses:
databricks warehouses get <warehouse-id> | jq '{name, warehouse_type, enable_serverless_compute}'
warehouse_type of CLASSIC with serverless off means a Python UDF won't run there. Point the dashboard at a pro or serverless warehouse, or rewrite the function in SQL. A SQL function is often faster anyway, because it's inlined into the query plan.
5. Python environment and sandbox
Python UDFs run in an isolated sandbox. They can't see the cluster's libraries, DBFS, workspace files or local disk. Declare packages on the function and pin the environment version:
CREATE OR REPLACE FUNCTION main.util.parse_sku(sku STRING)
RETURNS STRING
LANGUAGE PYTHON
ENVIRONMENT (
dependencies = '["/Volumes/main/util/wheels/sku_rules-1.4.0-py3-none-any.whl"]',
environment_version = '6'
)
AS $$
if sku is None:
return None
from sku_rules import normalise
return normalise(sku)
$$;
Points that commonly break:
- Dependency source. PyPI needs outbound internet. On a serverless SQL warehouse that depends on a networking setting that is in preview, so a wheel stored in a Unity Catalog volume is the safer choice. Depending on the environment version, callers may also need
READ VOLUMEon that volume. environment_version. It's required whenever you useENVIRONMENT. Supported values depend on the runtime: on classic DBR 16.2–18.1 it must be'None'. Check the current UDF documentation for your runtime.- NULLs. SQL
NULLarrives as PythonNone. An unguarded.upper()raises an error on the first null row and fails the whole query. - Network. On serverless and standard access mode compute, only TCP/UDP ports 80, 443 and 53 are allowed. A serverless egress policy can block those too.
- Secrets. Don't hard-code keys in the function body, because
DESCRIBE FUNCTION EXTENDEDshows it to anyone with access. Use Unity Catalog service credentials or the supported secrets integration for your runtime.
Fix and verify
After a fix, test as the identity that failed. Don't test as yourself. In a notebook or SQL editor, run as a member of the target group, or trigger the job once:
databricks jobs run-now <job-id>
Then check the result in query history:
SELECT start_time, executed_by, execution_status, error_message
FROM system.query.history
WHERE statement_text ILIKE '%main.util.mask_email%'
AND start_time > current_timestamp() - INTERVAL 1 HOUR
ORDER BY start_time DESC;
Prevent it next time
- Keep shared functions in one schema such as
main.util, owned by a group or deployment service principal, and deploy them from Git withCREATE OR REPLACE FUNCTION. - Grant
EXECUTEat schema level to consumer groups, so new functions work without another ticket. - Always call functions by their three-part name in jobs, views and dashboards.
- Prefer SQL UDFs. Use Python only when you need a library, and then pin
environment_versionand dependency versions. - Keep a smoke test in CI that calls each function on a pro or serverless warehouse with a NULL input and a normal input.
- Document which warehouses can run Python UDFs, and keep dashboards that use them off classic warehouses.
Get the weekly HubDatAI email
One email a week with everything new: posts, learning sessions and videos. Free, no spam, unsubscribe in one click. What you get