← All posts

Use Claude AI Inside Microsoft Fabric — A Beginner's Step-by-Step Guide

By the end of this post, your Fabric notebook will talk to Claude AI. You'll type a question in code, and Claude will answer — and then we'll use that to do something genuinely useful: automatically label a table full of customer comments.

You don't need any AI experience. If you can create a notebook in Fabric, you can do this. I'll explain every word.

What can you actually do with this?

Once your pipeline can talk to Claude, a whole class of "someone has to read this" work becomes automatic:

  • Classify and label data — tag support tickets by topic, mark comments as positive or negative, sort documents into categories. (This is what we'll build below.)
  • Validate your data — have AI review a table and flag rows that look wrong: a "refund" ticket labeled as "praise", a phone number in the email column, descriptions that don't match their category.
  • Extract structure from messy text — turn free-text notes, emails, or PDFs into clean columns: names, dates, amounts, order numbers.
  • Summarize — collapse 500 customer comments into "the top 5 complaints this week" for a dashboard.
  • Standardize — fix inconsistent values: "TX", "Texas", "texas " all become Texas.

The pattern is always the same: read rows → send them to Claude with instructions → write the answers back as new columns. Learn it once and every use case above is just a different instruction. So let's learn it.

First, three words explained

  • An API is just a way for your code to talk to a service on the internet. Your notebook sends a message, Claude sends an answer back. That's it.
  • An API key is like a password for your code. It proves the request is yours (and it's how usage gets billed to you — so we keep it secret).
  • Azure Key Vault is a safe in Azure where you store secrets like this key. Your notebook will open the safe when it runs. The key never sits in your code.

Here's the whole flow:

flowchart LR
    N["Your Fabric notebook"] -->|"1. get the key"| KV[("Key Vault (the safe)")]
    N -->|"2. send a question"| CL["Claude AI"]
    CL -->|"3. answer comes back"| N
    N -->|"4. save results"| LH[("Your lakehouse table")]
The flow: notebook → get key from Key Vault → ask Claude → save results to the lakehouse.

Four steps. Let's do them.

Step 1 — Get your API key

  1. Go to console.anthropic.com and create an account.
  2. In the billing section, add a little prepaid credit. $5 is plenty — the model we'll use costs less than a cent per question.
  3. Also set a monthly spend limit there. This means even if your code runs wild in a loop, it can never spend more than you allowed. Do this before anything else.
  4. Create an API key. It's a long code starting with sk-ant-. Copy it. You'll paste it exactly once — into the safe — and never again.

Step 2 — Put the key in the safe (Key Vault)

In the Azure portal:

  1. Search for Key VaultCreate. Pick your subscription, give it a name, choose Standard. Create it.
  2. Azure won't let even you touch the secrets until you give yourself the role. On your new vault, click Access control (IAM)Add role assignment → choose Key Vault Administrator → select your own account → save.
  3. Now click SecretsGenerate/Import. Name: ClaudeAPIKey. Value: paste your sk-ant- key. Create.
  4. Go back to the vault's Overview page and copy the Vault URI. It looks like https://yourvault.vault.azure.net/. Keep it handy for the next step.

Small heads-up: the role you gave yourself in point 2 can take a few minutes to activate. If Fabric says "permission denied" later, that's all it is — wait five minutes and try again.

Step 3 — Your first AI call from Fabric

In your Fabric workspace: + New itemNotebook.

Before writing anything, look at the language dropdown at the top and change it from PySpark to Python. Why? Talking to an API is light work — a Python notebook does it using a tiny slice of your capacity, while Spark would spin up a whole cluster for nothing. (This one setting is a big money-saver — I wrote about it in my CU post.)

Cell 1 — install the tools (run this once per session):

Python
%pip install anthropic deltalake duckdb

Cell 2 — talk to Claude:

Python
import anthropic
import notebookutils

# Open the safe and take out the key
key = notebookutils.credentials.getSecret(
    "https://yourvault.vault.azure.net/",   # <- your Vault URI from Step 2
    "ClaudeAPIKey"                          # <- your secret's name
)

# Connect to Claude using that key
client = anthropic.Anthropic(api_key=key)

# Ask something
msg = client.messages.create(
    model="claude-haiku-4-5",       # the small, fast, cheap model
    max_tokens=200,                 # limit on how long the answer can be
    messages=[
        {"role": "user", "content": "Say hello in one sentence."}
    ]
)

# Print the answer
print(msg.content[0].text)

Change only two things: the Vault URI and the secret name, to yours. Then run it.

If you see a friendly sentence printed — congratulations, that was your first AI API call. Your notebook opened the safe, got the key, asked Claude a question, and got an answer.

Why msg.content[0].text and not just msg? The answer arrives inside a little package, and the text is one item inside it. Try print(msg) once and you'll see the whole package — then the line makes sense.

If it fails instead: a permission error means the Key Vault role is still activating (wait a few minutes). A credit/billing error is actually good news — everything worked, the account just needs the credits from Step 1.

Step 4 — Now make it useful: label a table automatically

Saying hello is fun. Here's the real power.

Imagine a table of customer support tickets: a ticket_id and a comment the customer wrote. Someone used to read these and tag them by hand — "this one's about billing, this one's angry." We're going to have Claude do it for the whole table.

I'll break the code into small pieces so nothing is mysterious.

Piece 1 — read your table. DuckDB is a small tool that reads lakehouse tables without needing Spark:

Python
import duckdb

df = duckdb.sql("""
    SELECT ticket_id, comment
    FROM delta_scan('/lakehouse/default/Tables/dbo/tickets')
""").df()

print(df.head())   # look at what we loaded

Note we only take ticket_id and comment — Claude doesn't need the other columns, and sending less makes it cheaper and faster.

Piece 2 — write the instructions. We put all the comments into one message, and we tell Claude exactly how to answer:

Python
rows_text = "\n".join(
    f'{r.ticket_id}: "{r.comment}"' for r in df.itertuples()
)

prompt = f"""For each support ticket below, assign:
- category: one of billing, bug, feature, praise, outage
- sentiment: one of positive, negative, neutral

Tickets:
{rows_text}

Respond with ONLY a JSON array, no other text. Like this:
[{{"ticket_id": 1, "category": "billing", "sentiment": "negative"}}]"""

That last part — "ONLY a JSON array, no other text" — is the most important trick in this whole post. Without it, Claude answers like a helpful person ("Sure! Here are your tickets…") and your code can't use that. With it, you get clean data.

Piece 3 — send it:

Python
msg = client.messages.create(
    model="claude-haiku-4-5",
    max_tokens=2000,
    messages=[{"role": "user", "content": prompt}],
)
answer = msg.content[0].text
print(answer)   # you should see a clean JSON list

Piece 4 — turn the answer into a table and attach it to yours:

Python
import json, re
import pandas as pd

# Take just the part between [ and ] — a seatbelt in case
# the model ever adds a stray word around it
match = re.search(r"\[.*\]", answer, re.DOTALL)
labels = pd.DataFrame(json.loads(match.group()))

# Attach the new columns to the original rows by ticket_id
enriched = df.merge(labels, on="ticket_id")
print(enriched.head())

You now have your original tickets plus two new columns — category and sentiment — that Claude filled in.

Piece 5 — save it back to the lakehouse:

Python
from deltalake import write_deltalake

write_deltalake(
    "abfss://YourWorkspaceName@onelake.dfs.fabric.microsoft.com/"
    "YourLakehouseName.Lakehouse/Tables/dbo/enriched_tickets",
    enriched,
    mode="overwrite",
)

Replace YourWorkspaceName and YourLakehouseName with your real names — that long address is simply "where my lakehouse lives." Refresh your lakehouse and there it is: enriched_tickets, labeled by AI.

This works as-is for a few hundred tickets. For thousands, send them in batches of about 50 at a time inside a loop — same code, just wrapped in a for.

Step 5 — Make it run by itself

Create a pipeline, add a Notebook activity, point it at this notebook, add a schedule. Done. Every morning, new tickets get labeled before anyone's coffee is ready. And because the notebook takes the key from the safe on every run, changing the key later means updating one secret in Azure — your code never changes.

The short version

  1. Get a key at console.anthropic.com — add $5 credit and a spend limit first.
  2. Store the key in Azure Key Vault. It never appears in your code.
  3. In a Python (not PySpark) notebook: open the safe → connect → ask.
  4. For real work: read the table, demand "ONLY JSON" in your instructions, attach Claude's answers as new columns, save back.
  5. Schedule it in a pipeline and let it run.

I build this exact thing on camera — errors and all — on my YouTube channel. If reading it made sense, watching it will make it stick.

Keeping your Fabric capacity lean while you add AI?

Running AI calls in a Python notebook instead of Spark is one of the biggest CU savers in Fabric. I broke down the rest here.

How I Cut Fabric CU Usage 70% → 30% →
Murad Nabizade
Murad Nabizade

Data Engineer in Dallas, TX — Microsoft Fabric and Azure pipelines, data quality, and monitoring. I write about production Fabric and build free tools for data & QA engineers.