Zum Inhalt springen

Lektion 23 · Sharing, Governance and Performance

Custom SQL, Python, AI and Embedding

Extend Sigma with custom SQL, Python elements, AI features and secure embedding. Learn the key limits, permissions and safety checks before you use them.

Much work needs only tables and formulas. Sometimes you need more: a special query, a Python step, an AI helper, or a way to put analytics inside your own product. This lesson gives you a safe map of these extensions. Features here change quickly, so check Sigma's documentation (details below are as of December 2026).

Custom SQL

You can write SQL against a connection and use the result as a source. You need the Write SQL permission and access to the whole connection. Sigma wraps your query as a subquery, so statements that change data or structure (DDL and DML) and multiple statements are not supported. Sort order in SQL is not guaranteed, so sort in the table instead. Ordinal column references such as $1 are not supported.

Two special features:

  • Control values: wrap a control ID in double curly brackets; some control types need another form (see controls).
  • Other elements: sigma_element('Element title') queries another element in the same workbook. The title must match exactly. It has limits: not every connection supports it, elements using it cannot be materialized, and references to a grouped table return base rows.

Remember from the security lesson that sigma_element() does not carry column-level security with it. The next block is a read-only illustration, not tested in Sigma:

SQL
SELECT "Region", SUM("Amount") AS total
FROM sigma_element('Orders')
GROUP BY "Region"

Use custom SQL sparingly. Spreadsheet users find it harder to read, and it can affect performance. For the basics, see the SQL tutorial. The stand-in below shows a typical preparation step in portable SQL.

SQL Stand-in: a SQL step that prepares data for a table

Press Run (or Ctrl + Enter) to see the result here.

Python elements

Sigma can run Python on supported connections. According to the documentation, Python must be set up on the connection first, with guides for Databricks and Snowflake; other connections may not support it. Editing code needs the Write Python permission, and running it needs at least Can use access on the connection. Code runs on the data platform's compute. Calling external services needs network access to be allowed on that platform. For embedding, only JWT-signed secure embeds can include Python elements, and exporting or materializing Python output is not supported (schedules use the last run's output).

The method reference lists sigma.get_element() and sigma.output(), which takes a reference name without spaces and then the variable (some Sigma pages also write sigma_output(), so check the reference). A writeback destination argument applies to some connections. The snippet is illustrative and has not been run:

Python
orders = sigma.get_element("Orders")
# ... transform the data ...
sigma.output("orders_clean", orders)

Do not use Python for work that a formula does clearly. And never paste secrets into code.

AI features

Administrators decide which AI features are configured, and your account type must include them. Sigma's documentation lists, among others:

  • Sigma Assistant: ask questions about data in plain language and get answers, charts and tables; it can also help build content.
  • Formula assistant: write, fix and explain formulas.
  • Sigma agents: agents you configure with instructions, data sources and actions.
  • MCP server: connect external AI tools to Sigma.
  • AI-driven table output: call AI functions hosted by the data platform, for example to classify text.

AI output can be wrong in convincing ways. Check formulas on test rows, check query logic and compare totals. Understand where data goes: which model processes it, and which policy allows it. Do not give an agent more actions or data than it needs, and keep human approval for anything that changes records, sends messages or spends money. See AI agents for general safety ideas.

Python Stand-in: test a suggested formula before trusting it

Press Run (or Ctrl + Enter) to see the result here.

Program input · what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The failures show that zero and missing revenue need explicit rules.

Embedding

Embedding shows Sigma content inside another application. Sigma's documentation distinguishes public embeds from secure embeds. Secure embedding can use JSON Web Tokens (JWT): your server creates a token signed with a client secret, and the front end loads a URL that includes it. Key points:

  • The secret stays on your server, never in browser code.
  • Each token has a unique ID, and a reused token is rejected.
  • Claims such as user attributes or teams can support row-level security.
  • The documentation calls secure embed a premium feature, and setup needs admin rights or credentials from an admin.
  • Data models and reports can only be embedded securely.
TEXT
1. User signs in to your app
2. Browser asks your server for an embed URL
3. Server signs a short-lived token with the secret
4. Browser loads Sigma with that URL
5. Sigma verifies the token and shows allowed content

Never use a public embed for private data. Test that one customer can never see another customer's rows.

Automation and the API

Sigma has a REST API and ways to manage data models and workbooks as code. Give automation credentials minimal permissions, store secrets in a secret manager, log changes and test in a safe, non-production area first.

Common mistake: putting an embed secret or API key in front-end JavaScript. Anyone can read it. If a secret leaks, revoke it at once.

Choosing the simplest tool

Ask these questions in order. Can a table formula or grouping do it? Can a data model hold the logic for everyone? Only then consider custom SQL or Python. The earlier options are usually easier for colleagues to read and check. Record why you chose code, who maintains it and how it is tested.

A review checklist for code

Before others depend on a SQL or Python element, check that it selects only the columns it needs, respects the intended security rules, handles empty and null values and returns the grain its title promises. Ask a colleague to read it. Write a one-line note that says what it does.

Check your understanding

Quick check · 4 questions

of 4 answered You scored / 4 · perfect!

  1. 1. What kind of custom SQL does Sigma support, according to the docs?

    Sigma wraps SQL as a subquery, so DDL, DML and multiple statements are not supported.
  2. 2. Where must an embed client secret live?

    The server signs tokens, so the secret never reaches users.
  3. 3. How should you treat an AI-written formula?

    AI suggestions can look right and still be wrong.
  4. 4. What do Python elements need according to the docs?

    Python is configured per supported connection and needs permissions.

Summary

  • Custom SQL is limited to query-style statements; watch security exceptions.
  • Python elements need supported connections and permissions.
  • AI features need testing, data care and human approval for actions.
  • Secure embeds use server-signed tokens and must enforce per-user rules.
  • Protect secrets and test automation safely.

Next: Project: Sales Dashboard

Dein Fortschritt wird in diesem Browser gespeichert. Kein Konto nötig.