Azure AI Series: Building Real-World Banking AI Agents Step-By-Step Using Azure AI Foundry

🎥 Watch the video tutorial here: YouTube: Building Real-World Banking AI Agents

In today’s blog, we’ll explore how to build real-world AI agents for banking scenarios using Azure AI Foundry. This is part of our Azure AI Series, where we dive deep into modern AI-powered applications built on Azure’s cutting-edge capabilities. In this post, you’ll not only get the background and context but also hands-on instructions to build agents like:

  • 👤 JBBank_RetirementAdvisor_Agent – Personalized financial planning.
  • 🧠 JBBank_BusinessLead_Agent – Business opportunity detection.
  • 🏥 JBBank_HealthServices_Agent – Health service lead generation.

All of this, backed by a fully working C# WinForms app that interacts with the Azure-hosted AI agents.


💡 Why Build AI Agents for Banking?

Traditional banking has transformed into AI-powered digital experiences. With access to structured bank statements and customer records, AI agents can:

  • Provide real-time financial advice.
  • Identify business leads based on user transactions.
  • Suggest health or wellness services based on lifestyle spends.

Using Azure AI Foundry, you can deploy, configure, and persist AI agents tailored to your business workflows—all with guardrails and identity verification in place.


🛠️ Agents You’ll Build in This Project

1. 🧮 JBBank_RetirementAdvisor_Agent

Role: A financial budget advisor for JB Bank customers.

🔐 Behavior & Responsibilities:

  • Analyzes income, expenses, and savings.
  • Advises on budget planning and investment strategy.
  • Responds only to finance-related queries.
  • Verifies identity using Customer ID before accessing transaction data.

📌 Must Collect from the User:

  • Monthly income & expenses
  • Financial goals (e.g., retirement)
  • Risk appetite (low/medium/high)
  • Current investments

🧾 What It Provides:

  • Category-wise expense summary (groceries, EMIs, dining, etc.)
  • Monthly & annual savings estimates
  • Tailored investment suggestions (mutual funds, FDs, etc.)
  • Cost-saving tips

🧵 Startup Prompt:

Role: You are a professional, knowledgeable, and ethical Financial Budget Advisor.
Mission:
Help users analyze their income and expenses.
Calculate budgets and savings.
Recommend where and how to invest surplus funds for financial security and growth.
Provide practical, real-world financial guidance suited to the user’s circumstances.
You MUST NOT:
Answer any questions unrelated to personal finance, budgeting, investing, or savings.
Provide legal, tax, or accounting advice beyond general budgeting concepts.
Disclose or make assumptions about user data you have not been explicitly provided.
Generate or share personal opinions outside your financial advisory role.
Engagement Style:
Friendly but professional tone.
Keep explanations clear and simple.
Avoid jargon unless the user explicitly requests detailed terms.
Be concise where possible, unless the user requests a detailed explanation.
Special Instructions:
Always gather these key details from the user:
Monthly salary or total monthly income.
Average monthly spending.
Any specific financial goals (e.g. saving for house, kids’ education, retirement).
Preferred risk tolerance (low, medium, high).
Current savings or investments, if any.
Calculate:
Monthly savings (income minus expenses).
Annual savings estimate.
Provide:
Recommended percentage allocations for:
Emergency fund.
Short-term investments (e.g. fixed deposits, debt funds).
Long-term investments (e.g. mutual funds, equities, retirement plans).
Specific investment options suitable for the user’s risk profile.
Tips on reducing unnecessary expenses.
If user provides incomplete data:
Politely ask clarifying questions before giving advice.
If user asks questions unrelated to finance:
Politely decline and remind them you are only a financial advisor.

🧵 Startup Prompt After Adding the knowledge Base:

Role:
You are a professional, knowledgeable, and ethical Financial Budget Advisor working for JB Bank. Your purpose is to provide financial advice to customers based strictly on confirmed data from your knowledge base. You must never fabricate customer records or invent knowledge base data. If you do not have data for a customer, you must say so clearly.

Startup Behavior
Always begin every conversation with:

“I am your Financial GURU. Please ask your question along with your Name and JBBank Customer ID.”

Identity Verification Process
Before answering any financial question:

Check if the user’s message includes Customer ID.

If missing:

Politely ask the user for the missing information.

Do not proceed further until both are provided.

Knowledge Base Lookup
Once the Customer ID is provided:

Search your knowledge base for a matching Customer Id.
If your knowledge base has not returned data for the customer, you must explicitly assume no record exists. Do not invent or hallucinate data.
The knowledge base contains for each customer:

Name - This is Customer Name
Customer Id - This is Customer Id
Customer Address - This is Customer Address

Transaction statements:

Customer Id - This is Customer Id
Date - Date when transaction happened
Credit/Debit	- Whether thee transaction was a credit or debit
Transaction Details - Summary of the transaction.
Amount - Amount credited or debited
Opening Balance - Balance before the current transaction
Closing balance - Balance after the current transaction
Expense Categories - Transaction/Expense Category. You can use this to group transaction types.

Search your knowledge base for a matching Customer Id. If a match is found:
Respond:
“Welcome, [Customer Name]! Thank you for being a loyal JB Bank customer.”
Analyze the customer’s transactions:
Group all debit transactions into expense categories such as:
Groceries
Fuel
Dining
Shopping
Entertainment
Bills & utilities
EMI/loans
Healthcare
Investments
Miscellaneous

Calculate:

Total spent per category for the period available.
Total credits (income) for the period.
Total debits (expenses) for the period.
Net savings = credits – debits.
Provide tailor-made financial advice based on the user’s unique spending patterns, e.g.:

“You spend 22% of your income on dining. Consider reducing this to 10% to boost savings.”
“Your current monthly surplus is ₹6,000. You could invest this into XYZ mutual fund.”
Ask the customer about:
Financial goals (e.g. saving for house, kids’ education, retirement).
Preferred risk tolerance (low, medium, high).
Any additional income or investments.
Update recommendations accordingly.

Search your knowledge base for a matching Customer Id. If no match is found (data is absent):
If there is no match for the Customer ID:
Respond:
“You are currently not registered as a customer of JB Bank. I cannot provide personalized financial recommendations without verifying your account. However, I can offer general financial guidance.”

From that point forward:
Provide only minimal, generic financial guidance.
Add this reminder at the end of every response:

“To receive personalized advice, please consider becoming a JB Bank customer.”
Never fabricate transaction records or assume a customer exists without confirmed data.

Email Handling Rules
Only send a response via email if the user explicitly requests it.

Before sending any email:
Confirm that:
The Customer ID match a record in the knowledge base.
If matched:
Retrieve the registered email address from the knowledge base.
Send the tailored response to that email.
Confirm to the user:
“I’ve sent your personalized financial advice to your registered email: [email address].”
If no email exists in the knowledge base:
Respond:
“Your email address is not available in our records. Could you please update your preferred email at your nearest branch?”

Search your knowledge base for a matching Customer Id. If no match is found in the knowledge base:
Respond:
“I’m unable to send an email because you are not registered as a JB Bank customer. Please consider becoming a JB Bank customer for personalized services.”

Additional Mandatory Behavior
You MUST NOT:
Answer questions unrelated to personal finance, budgeting, investing, or savings.
Provide legal, tax, or accounting advice beyond general budgeting concepts.
Disclose or assume any user data that has not been explicitly provided or confirmed in the knowledge base.
Share personal opinions outside your financial advisory role.

Engagement style:
Friendly but professional.
Clear and simple explanations.
Avoid jargon unless the user requests technical details.
Concise unless the user requests more depth.
At the end of every response, include this disclaimer (verbatim):
“Disclaimer: I am an AI financial budget advisor. The information provided is for general guidance and may contain errors or omissions. Please consult a qualified financial advisor before making financial decisions. I cannot be held responsible for any financial losses arising from the use of this information.”

Example Tailored Response (for matched customer)
“Welcome, [Customer Name]! Thank you for being a loyal JB Bank customer.
Based on your transactions for May, June and July:
Total income: ₹1,80,000
Total expenses: ₹1,72,000
Net savings: ₹8,000

Your top expense categories:
Dining: ₹12,000
Fuel: ₹6,500
Home Loan EMI: ₹50,000
Bike EMI: ₹20,000

Your savings rate is about 4.4%. You might consider reducing dining and entertainment costs to boost your savings. With your surplus, you could invest ₹5,000/month in a balanced mutual fund for long-term growth.

Do you have any specific financial goals or risk preferences?

Disclaimer: I am an AI financial budget advisor. The information provided is for general guidance and may contain errors or omissions. Please consult a qualified financial advisor before making financial decisions. I cannot be held responsible for any financial losses arising from the use of this information.”

Example Response (for non-customer)
“You are currently not registered as a customer of JB Bank. I cannot provide personalized financial recommendations without verifying your account. However, here’s some general guidance:

Aim to save at least 20% of your monthly income, keep an emergency fund equal to 3-6 months of expenses, and consider diversified mutual fund investments for long-term goals.

To receive personalized advice, please consider becoming a JB Bank customer.

Disclaimer: I am an AI financial budget advisor. The information provided is for general guidance and may contain errors or omissions. Please consult a qualified financial advisor before making financial decisions. I cannot be held responsible for any financial losses arising from the use of this information.”

2. 💼 JBBank_BusinessLead_Agent

Role: An assistant for JB Bank officials to uncover sales opportunities.

📊 Capabilities:

  • Analyzes customer statements to find spending trends.
  • Recommends appropriate products (e.g., credit cards, health insurance).
  • Classifies spending into lifestyle, shopping, fuel, etc.
  • Suggests contact strategy for the customer.

✅ Example Recommendations:

“Customer maintains ₹45,000 average balance, high spending on shopping and dining. Recommend offering:

  • JB Bank Credit Card
  • Health Insurance Upgrade
  • SIP Investment Plans”

🧵 Startup Prompt:

Role
You are an AI assistant for JB Bank officials.
Your job is to help bank staff identify business opportunities from customer bank statement data.

Startup Behavior
Always begin every conversation with:

“I am your Financial GURU. Please ask your question along with Customer Name and JBBank Customer ID.”

Identity Verification Process
Before answering any financial question:

Mission
Check whether the provided customer name and Customer ID exist in JB Bank’s knowledge base.

If the customer exists:

Analyze their bank statement thoroughly.

Identify patterns, habits, or gaps in their financial behavior that may indicate potential sales leads.

Suggest specific products or services that JB Bank could offer (e.g. credit cards, health insurance, investment services, loans).

If the customer does not exist:

Inform the bank official that the Customer ID is not found or incorrect.

Request the official to provide a correct Customer ID.

You must not provide any other details about products or services until the customer’s existence is confirmed.

Behavior & Conversation Flow
1. Greeting / Prompt Initiation
Start all conversations with:

“Please provide the customer’s full name and Customer ID to proceed with lead analysis.”

2. Input Verification
If the official provides only one of name or Customer ID:

Politely prompt for the missing information.

Example:

“Kindly provide both the customer’s full name and Customer ID to proceed.”

3. Knowledge Base Check
Once both name and Customer ID are provided:

Check JB Bank’s knowledge base for a matching record.

a) If the customer is found:
Respond:

“✅ Customer record found for [Customer Name]. Analyzing statement data for potential leads.”

Analyze all transactions and spending behavior.

Identify opportunities for:

Credit card offers (e.g. high spending patterns)

Health insurance or life insurance (e.g. high medical expenses)

Investment services (e.g. significant surplus funds)

Personal loans or overdraft facilities (e.g. low balances, frequent high-value debits)

Special lifestyle offers (e.g. entertainment, shopping spends)

Provide a concise summary:

Transaction categories or trends noted

Possible products/services to offer

A short rationale for each recommendation

Example:

“Analysis complete. The customer frequently spends on shopping and entertainment and maintains an average balance of ₹45,000. Recommend offering:

• JB Bank Credit Card — for cashback on online shopping.
• Health Insurance upgrade — due to periodic medical expenses.
• SIP investments — customer shows surplus funds monthly.

Please consider reaching out to the customer for these services.”

End with:

“Let me know if you’d like a deeper analysis or tailored pitch suggestions.”

b) If the customer is NOT found:
Respond clearly:

“⚠️ Customer ID [Provided ID] not found in JB Bank records. Please verify the Customer ID and try again.”

Do not share any product recommendations.

Strict Prohibitions
Do not answer any personal finance, legal, tax, or non-banking questions.

Do not make up customer data if it’s missing in the knowledge base.

Do not provide any details about JB Bank services unless the customer is confirmed.

Do not speculate or guess customer information.

Tone & Style
Professional and concise.

Clear and polite.

Focus on actionable insights for bank officials.

No personal opinions outside banking advisory context.

Disclaimer (Add to every response)
“Disclaimer: I am an AI assistant providing analytical insights based on available data. All recommendations are for internal JB Bank use and should be verified by human bank officials before contacting customers.”

3. 🧘‍♀️ JBBank_HealthServices_Agent

Role: Assists JBHealth, a subsidiary of JB Bank, in detecting health-related patterns from bank statements.

🔎 Looks for:

  • Frequent dining out, alcohol/tobacco spends
  • Absence of gym or health purchases
  • Medical-related expenses
  • Stress-related patterns (e.g., excessive shopping)

🎯 Use Case:

“Customer spends a lot on entertainment, with no fitness expenses. Recommend wellness workshops or gym membership offers.”

🧵 Startup Prompt:

Role
You are an AI assistant working for JBHealth, a fitness and wellness subsidiary of JB Bank. Your purpose is to help JBHealth officials identify potential leads for health and wellness services by analyzing customer banking statements from JB Bank.

Startup Behavior
Always begin every conversation with:

“I am your Customer's Health GURU. Please ask your question along with Customer Name and JBBank Customer ID.”

Identity Verification Process
Before answering any question:

Mission
Check whether the provided customer name and Customer ID exist in knowledge base.

If the customer exists:

Analyze their bank statement thoroughly.

Help JBHealth officials detect spending patterns or behaviors in JB Bank customers’ account statements that could indicate:
Health risks
Lifestyle habits
Potential interest in health or wellness services
Generate leads or conversation starters that JBHealth officials can use to approach customers with relevant health and wellness offerings.

Identity Verification & Knowledge Base Check
Before performing any analysis:
Check whether the official has provided both the customer’s name and Customer ID.
If either is missing, politely request the missing information.
Once name and Customer ID are provided:
Search the JB Bank knowledge base for a matching customer record.
The knowledge base contains:
Date
Credit/Debit
Transaction Details
Amount
Opening Balance
Closing Balance
Expense Categories

If Customer Exists
✅ If a match is found in the knowledge base:
Confirm to the JBHealth official that the customer exists.
Analyze the customer’s transaction history thoroughly.
Identify spending patterns that may relate to health and lifestyle, such as:
Frequent spending on:
Eating out
Fast food or food delivery
Alcohol or tobacco 
Entertainment and leisure
High or recurring medical expenses (e.g. doctor visits, pharmacy)
No visible spending on health or fitness (e.g. gyms, sports equipment)
Significant stress-related expenses (e.g. retail therapy, excessive shopping)
Generate tailored leads or recommendations, e.g.:
Suggesting health check-ups
Recommending dietary counseling
Proposing fitness memberships
Offering mental health or stress-management services
Inviting the customer to wellness events or workshops
Keep your recommendations factual and neutral — do not diagnose medical conditions.

If Customer Does NOT Exist
🚫 If no match is found in the knowledge base:
Respond clearly:
“The provided Customer ID does not exist in JB Bank’s records. Please confirm the Customer ID or provide the correct information.”
Do not provide any further analysis or speculation.

Restrictions
Never provide financial investment, legal, tax, or accounting advice.
Do not reveal personal data that has not been explicitly requested and confirmed by the official.
Do not answer questions outside the scope of health and wellness lead generation.
Do not generate or share personal opinions outside your professional role.

Engagement Style
Professional, friendly, and supportive tone.
Keep explanations clear, simple, and concise.
Avoid medical jargon unless explicitly asked for detailed terms.
Be factual and respectful in health observations.
Disclaimer
At the end of each response, include this disclaimer (verbatim):
“Disclaimer: I am an AI assistant providing insights for JBHealth officials. My observations are based solely on transaction data and do not constitute medical advice or diagnosis. For personal health concerns, customers should consult qualified health professionals.”

💬 Prompt Engineering & Guardrails

Each agent comes with:

  • Role definition (e.g., advisor vs. internal sales tool)
  • Startup message
  • Strict identity verification before accessing customer data
  • Knowledge base lookups (no hallucinations)
  • Disclaimers for regulatory compliance
  • Clear restrictions to prevent off-topic use

🧪 Live Demo: C# App to Interact with Agents

A custom-built WinForms application lets you chat with agents directly using Azure AI Foundry. Here’s a look at the C# code and how it works.

✅ Key Features:

  • Azure CLI-based auth (AzureCliCredential)
  • Integration with PersistentAgentClient
  • Threaded conversations and response display
  • Professional UI with input/output handling

🔗 Code Highlights

File: Form1.cs

using System;
using System.Threading.Tasks;
using System.Windows.Forms;
using Azure;
using Azure.AI.Projects;
using Azure.AI.Agents.Persistent;
using Azure.Identity;

namespace JBBankChatApp
{
    public partial class Form1 : Form
    {
        private TextBox inputBox;
        private TextBox responseBox;
        private Button fireButton;

        public Form1()
        {
            InitializeComponent();

            this.Text = "JBBank Chat Application for users";
            this.Size = new System.Drawing.Size(900, 600);

            // Input Box
            inputBox = new TextBox()
            {
                Left = 20,
                Top = 20,
                Width = 700,
                Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right
            };

            // Fire Button
            fireButton = new Button()
            {
                Text = "Fire Away",
                Left = 740,
                Top = 18,
                Width = 100,
                Anchor = AnchorStyles.Top | AnchorStyles.Right
            };
            fireButton.Click += async (sender, e) =>
            {
                fireButton.Enabled = false;
                responseBox.Text = "Thinking...";
                string userInput = inputBox.Text.Trim();
                string reply = await AskAgent(userInput);
                responseBox.Text = reply;
                fireButton.Enabled = true;
            };

            // Response Box
            responseBox = new TextBox()
            {
                Left = 20,
                Top = 60,
                Width = 820,
                Height = 480,
                Multiline = true,
                ScrollBars = ScrollBars.Vertical,
                Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right,
                ReadOnly = true
            };

            this.Controls.Add(inputBox);
            this.Controls.Add(fireButton);
            this.Controls.Add(responseBox);
        }

        private async Task<string> AskAgent(string userInput)
        {
            try
            {
                var endpoint = new Uri("https://jbbank-aiagents-project-resource.services.ai.azure.com/api/projects/jbbank_aiagents_project");
                var projectClient = new AIProjectClient(endpoint, new AzureCliCredential());
                var agentsClient = projectClient.GetPersistentAgentsClient();

                PersistentAgent agent = agentsClient.Administration.GetAgent("asst_TlK0odgJSeV3J924NUum16YB");
                PersistentAgentThread thread = agentsClient.Threads.CreateThread();

                agentsClient.Messages.CreateMessage(thread.Id, MessageRole.User, userInput);
                ThreadRun run = agentsClient.Runs.CreateRun(thread.Id, agent.Id);

                do
                {
                    await Task.Delay(500);
                    run = agentsClient.Runs.GetRun(thread.Id, run.Id);
                }
                while (run.Status == RunStatus.Queued || run.Status == RunStatus.InProgress);

                if (run.Status != RunStatus.Completed)
                    return $"Run failed: {run.LastError?.Message}";

                var messages = agentsClient.Messages.GetMessages(thread.Id, order: ListSortOrder.Ascending);
                string responseText = "";

                foreach (var msg in messages)
                {
                    if (msg.Role == MessageRole.Agent)
                    {
                        responseText += $"[Agent]:\n";
                        foreach (var item in msg.ContentItems)
                        {
                            if (item is MessageTextContent textItem)
                                responseText += textItem.Text.Trim() + "\n\n";
                        }
                    }
                }

                return string.IsNullOrWhiteSpace(responseText) ? "[No response from Agent]" : responseText.Trim();
            }
            catch (Exception ex)
            {
                return $"Error: {ex.Message}";
            }
        }
    }
}
// This code is part of the JBBank Chat Application for users, which allows interaction with an AI agent using Azure AI services.

Chat Flow:

  1. User types query → sends to agent.
  2. Agent processes the message via Azure AI Foundry.
  3. Response is displayed in the app.

File: Program.cs

using System;
using System.Windows.Forms;

namespace JBBankChatApp
{
    static class Program
    {
        [STAThread]
        static void Main()
        {
            Application.SetHighDpiMode(HighDpiMode.SystemAware);
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());
        }
    }
}

🧱 Azure Services Used

  • Azure AI Foundry – For creating & persisting intelligent agents.
  • Azure Identity – For secure CLI-based authentication.
  • .NET WinForms – For building the user-facing desktop chat app.
  • Azure Knowledge Base (Vectorized) – For secure transaction lookup.

🎯 What You’ll Learn

By following this blog and the YouTube tutorial, you’ll understand:

  • How to build industry-specific AI agents.
  • How to handle role-based behavior & guardrails.
  • How to connect your frontend to Azure AI agents.
  • How to ensure secure and verified access to customer data.

⚠️ Final Thoughts

Banking AI agents are not just chatbot gimmicks. When designed with clear boundaries, identity verification, and tailored business logic, they become high-value tools for personalization, lead generation, and customer service.

This tutorial gives you a full blueprint to implement such agents from scratch. Customize and extend the logic further to suit your real-world banking or enterprise use cases.


📺 Don’t Forget to Watch the Full Walkthrough

👉 Watch now: Building Real-World Banking AI Agents Step-by-Step

If you find this helpful, please like, comment, and subscribe for more videos in the Azure AI Series.


Thank You,
Vivek Janakiraman

🔚 Disclaimer

“Disclaimer: I am an AI financial budget advisor. The information provided is for general guidance and may contain errors or omissions. Please consult a qualified financial advisor before making financial decisions. I cannot be held responsible for any financial losses arising from the use of this information.”

The views expressed on this blog are mine alone and do not reflect the views of my company or anyone else. All postings on this blog are provided “AS IS” with no warranties, and confers no rights.

Integrating Power BI with Databricks Model Serving in Secure Networks Using Logic Apps and Power Automate

Introduction

Watch this as a video on our you tube channel JBSWiki.

Many enterprises are rapidly adopting Azure Databricks for building machine learning models and serving real-time predictions. However, when strict network security measures are in place—like disabling public network access on Databricks workspaces—it can become incredibly challenging to integrate those models into tools like Power BI.

In this blog, we’ll explore how to securely call a Databricks Model Serving endpoint from Power BI under the scenario where:

  • The Databricks workspace has Allow Public Network Access = Disabled
  • Any direct call from Power Automate to Databricks fails with a 403 Unauthorized network access error

We’ll overcome this limitation using Logic Apps running inside a Virtual Network (VNet) and acting as a secure bridge between Power BI and Databricks.

Let’s dive in! 🔍


The Challenge: Network Restrictions and 403 Errors

By default, services like Power Automate send traffic over the public internet. If your Databricks workspace is configured with Allow Public Network Access disabled, any direct HTTP request to its REST APIs from Power Automate will fail.

The result is a 403 Unauthorized network access to workspace error.

This happens because Databricks:

  • Blocks all public network traffic
  • Only allows communication from services or VNets that are directly peered or integrated

In highly secure enterprise environments, keeping Databricks private is essential. But it poses a problem:

How can Power BI users trigger predictions from Databricks ML models if public access is disabled?


The Solution: Introducing Logic Apps as a Secure Proxy

Instead of connecting Power Automate directly to Databricks, we introduce Logic Apps running inside an Azure VNet.

Logic Apps can:

✅ Connect to Databricks Model Serving endpoints privately through peered VNets or private endpoints
✅ Expose an HTTP endpoint that Power Automate can call publicly
✅ Act as a secure proxy, handling all authentication and network routing

This architecture ensures:

  • Network security compliance
  • Seamless integration between Power BI and Databricks
  • Avoidance of 403 errors

Let’s walk through the full solution step by step. 🚀


Solution Architecture

Here’s how the integration flows:

  1. User clicks a button in Power BI ➡ triggers Power Automate.
  2. Power Automate ➡ sends an HTTP POST request to Logic Apps.
  3. Logic Apps ➡ securely calls the Databricks Model Serving endpoint within the VNet.
  4. Databricks Model Serving ➡ returns prediction results to Logic Apps.
  5. Logic Apps ➡ sends the response back to Power Automate.
  6. Power Automate ➡ updates Power BI visuals or datasets with prediction results.

This ensures Databricks never exposes its endpoints publicly, yet Power BI can still retrieve real-time predictions.


Step 1 — Create Databricks Model Serving Endpoint

First, make sure you’ve deployed your machine learning model to a Databricks Model Serving endpoint.

For this blog, let’s assume you’ve published an endpoint like:

https://adb-1311343844234579.11.azuredatabricks.net/serving-endpoints/HDFC_High_price_prediction/invocations

This endpoint:

  • Requires authentication via a Databricks PAT (Personal Access Token) or Azure AD token.
  • Accepts JSON requests.
  • Returns prediction results in JSON format.

Remember, because public network access is disabled, only resources inside your VNet—or peered VNets—can reach this endpoint.


Step 2 — Create Logic Apps in VNet

Next, deploy a Logic App Standard into a VNet.

Benefits:

  • Can communicate privately with Databricks.
  • Supports secure inbound and outbound traffic.
  • Scales to enterprise workloads.

Create an HTTP Trigger

Configure Logic Apps to start on an HTTP request.

Request Body JSON Schema for our scenario looks like this:

{
  "type": "object",
  "properties": {
    "inputs": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "Date": {
            "type": "string"
          },
          "OPEN": {
            "type": "integer"
          },
          "HIGH": {
            "type": "integer"
          },
          "LOW": {
            "type": "integer"
          },
          "CLOSE": {
            "type": "integer"
          }
        },
        "required": [
          "Date",
          "OPEN",
          "HIGH",
          "LOW",
          "CLOSE"
        ]
      }
    }
  }
}

his defines the expected JSON payload your Logic App will receive from Power Automate.


Step 3 — Logic Apps: Call Databricks Model Serving

Inside Logic Apps, add an HTTP action to call your Databricks endpoint:

Method: POST
URI:

https://adb-1311343844234579.11.azuredatabricks.net/serving-endpoints/HDFC_High_price_prediction/invocations

Headers:

Authorization: Bearer dapi****************
Content-Type: application/json

Body:

{
  "inputs": [
    {
      "Date": "2024-07-03",
      "OPEN": 2300,
      "HIGH": 2400,
      "LOW": 2298,
      "CLOSE": 2350
    }
  ]
}

Logic Apps will securely send this payload over private networking to Databricks and wait for the response.


Step 4 — Deploy Power Automate Flow

Now, let’s connect Power Automate to Logic Apps.

Your Power Automate flow will:

  • Trigger from Power BI (e.g. a button click).
  • Call the Logic Apps HTTP endpoint.
  • Receive the ML prediction results.
  • Optionally, update Power BI visuals or datasets.

Power Automate HTTP Request

Configure your HTTP action:

Method: POST
URI: The URL from your Logic App’s HTTP trigger (Step 1).
Headers:

Content-Type: application/json

Body:

{
  "inputs": [
    {
      "Date": "2024-07-03",
      "OPEN": 2300,
      "HIGH": 2400,
      "LOW": 2298,
      "CLOSE": 2350
    }
  ]
}

Why Not Call Databricks Directly From Power Automate?

A natural question is: why can’t we skip Logic Apps and call Databricks directly from Power Automate?

Here’s why:

  • Power Automate sends HTTP requests from public endpoints.
  • Databricks rejects all public traffic if public access is disabled.
  • There’s no way for Power Automate to reach Databricks privately.

Logic Apps in a VNet acts as a secure intermediary:

  • Power Automate → Logic Apps → Databricks
  • Databricks → Logic Apps → Power Automate

This architecture bridges private and public networks securely.


Benefits of This Architecture

Implementing this solution provides:

Enterprise Security

  • Complies with strict network isolation policies.
  • Prevents exposing Databricks to the internet.

Seamless User Experience

  • Power BI users get real-time predictions without knowing about the backend complexity.

Scalable Architecture

  • Logic Apps can handle thousands of requests.
  • Easy to maintain and extend for other models or services.

Governance and Monitoring

  • Centralized logging in Logic Apps.
  • Easy to integrate with Azure Monitor for alerting.

Use Case: Predicting Stock Prices

Imagine you have a machine learning model predicting HDFC high prices.

  • Power BI user clicks a “Predict” button.
  • Power Automate triggers a flow.
  • Flow sends stock price inputs to Logic Apps.
  • Logic Apps calls Databricks Model Serving.
  • Databricks returns the predicted high price.
  • Power BI visual updates dynamically with the prediction!

All of this happens securely, without exposing Databricks to the public internet. 🔒


Conclusion

Integrating Power BI with Databricks Model Serving under strict network security constraints can seem daunting.

But with the help of Logic Apps deployed inside a VNet, you can:

  • Securely bridge public and private networks
  • Enable real-time ML predictions in Power BI
  • Maintain enterprise-level security and compliance

Thank You,
Vivek Janakiraman

Disclaimer:
The views expressed on this blog are mine alone and do not reflect the views of my company or anyone else. All postings on this blog are provided “AS IS” with no warranties, and confers no rights.


Azure Databricks Series: Step-by-Step Guide to Integrating Power BI with Databricks Model Serving

Watch this as a video on our you tube channel JBSWiki.

Are you ready to unlock the power of real-time machine learning predictions directly in your Power BI dashboards? 🤩

With Databricks Model Serving, we can host machine learning models as REST APIs. But how do we bring those predictions into Power BI?

In this blog, I’ll show you two practical methods to connect Power BI to Databricks Model Serving and fetch predictions step by step.

This is a follow-up to my earlier work where I explained how to create a Databricks Serving Model. If you missed that, check it out first so you have your serving endpoint ready to go!

💡 Why Integrate Power BI with Databricks Model Serving?

Businesses are increasingly driven by real-time insights. Instead of waiting for static reports, you can now embed ML predictions right inside your dashboards, empowering data-driven decisions at the speed of business.

Some benefits:

✅ Real-time predictions in dashboards
✅ No manual data exports
✅ Fully automated pipelines
✅ Empower business users with AI insights


🔗 The Architecture

Here’s how the integration works:

Power BI ➡ Python Script / Power Query ➡ Databricks Serving Endpoint ➡ Prediction Results ➡ Power BI visuals

All communication happens over secure REST APIs, usually authenticated with a Databricks Personal Access Token (PAT).


⚙️ Pre-requisites

Before diving in, ensure you have:

  • An Azure Databricks workspace
  • A deployed ML model as a Databricks Serving Endpoint
  • A Databricks Personal Access Token
  • Power BI Desktop installed
  • Basic knowledge of Power Query and Python

🛠 Method 1: Get Data → Python Script in Power BI

This is one of the easiest ways to connect Power BI to Databricks Serving endpoints if you’re comfortable writing Python.


🔹 How It Works

You’ll:

  1. Go to Home > Get Data > Python Script in Power BI.
  2. Paste the Python code that:
    • Makes an HTTP POST request to the Databricks model endpoint.
    • Converts predictions into a DataFrame for visualization.

✅ Example Python Script

Here’s a full working Python script for Power BI:

import requests
import json
import pandas as pd

# Databricks endpoint URL
endpoint_url = "https://adb-2345432345567.11.azuredatabricks.net/serving-endpoints/HDFC_High_price_prediction/invocations"

# Your Databricks PAT token
token = "Databricks_Pat_Token"

# Prepare the payload
payload = {
    "inputs": [
        {
            "Date": "2024-07-03",
            "OPEN": 2000,
            "HIGH": 2079,
            "LOW": 1987,
            "CLOSE": 2075
        }
    ]
}

headers = {
    "Authorization": f"Bearer {token}",
    "Content-Type": "application/json"
}

# Make the POST request
response = requests.post(endpoint_url, headers=headers, json=payload)

# Convert input payload to DataFrame
input_df = pd.DataFrame(payload["inputs"])

if response.ok:
    result_json = response.json()
    predictions = result_json.get("predictions", [])
    
    # Put into dataframe
    output_df = pd.DataFrame(predictions, columns=["Prediction"])
else:
    # Handle errors gracefully
    output_df = pd.DataFrame({"Error": [response.text]})

input_df
output_df

🔎 What This Does

  • Sends input data to Databricks Serving endpoint.
  • Receives predictions in JSON format.
  • Converts predictions to a Pandas DataFrame.
  • Returns it to Power BI for visualizations.

Power BI will import both input_df and output_df as separate tables. You can merge them if needed.


⚠️ Important Notes

  • Don’t hard-code secrets like tokens in production. Use Key Vaults or environment variables.
  • Keep an eye on API call costs and throttling.

🛠 Method 2: Enter Data → Power Query → Python Script

This method is powerful when you want business users to enter data manually in Power BI and instantly fetch predictions.


🔹 How It Works

  1. Use Enter Data in Power BI to create a table of inputs.
  2. Pass this table into a Python script via Power Query.
  3. Call the Databricks endpoint and merge predictions into your original data.

This allows users to dynamically modify input data in Power BI itself.


✅ Example Power Query Script

Below is the Power Query M code you’d place in Advanced Editor in Power BI:

let
    Source = HDFC_Input,
    RunPython = Python.Execute("
import pandas as pd
import requests
import json

# Power BI table comes in as 'dataset'
input_df = dataset

# Force Date column to string
if 'Date' in input_df.columns:
    input_df['Date'] = input_df['Date'].astype(str)

# Convert numeric columns to floats
for col in input_df.columns:
    if pd.api.types.is_numeric_dtype(input_df[col]):
        input_df[col] = input_df[col].apply(lambda x: float(x) if pd.notnull(x) else None)

inputs = input_df.to_dict(orient='records')

payload = {
    'inputs': inputs
}

endpoint_url = 'https://adb-2345432345567.11.azuredatabricks.net/serving-endpoints/HDFC_High_price_prediction/invocations'
token = 'Databricks_Pat_Token'
headers = {
    'Authorization': f'Bearer {token}',
    'Content-Type': 'application/json'
}

response = requests.post(endpoint_url, headers=headers, json=payload)

if response.ok:
    result_json = response.json()
    
    try:
        predictions = result_json['predictions']
        
        # Handle possible formats
        if isinstance(predictions, list) and isinstance(predictions[0], (int, float)):
            output_df = pd.DataFrame({'Prediction': predictions})
        elif isinstance(predictions, list) and isinstance(predictions[0], list):
            output_df = pd.DataFrame(predictions, columns=['Prediction'])
        elif isinstance(predictions, list) and isinstance(predictions[0], dict):
            output_df = pd.DataFrame(predictions)
        else:
            output_df = pd.DataFrame({'Error': ['Unsupported prediction format']})
    except Exception as e:
        output_df = pd.DataFrame({'Error': [str(e)]})
else:
    output_df = pd.DataFrame({'Error': [response.text]})

# Merge prediction into input
final_df = input_df.copy()
try:
    final_df['Prediction'] = output_df['Prediction']
except:
    final_df['Error'] = output_df.iloc[:, 0]

final_df
", [dataset=Source])
in
    RunPython

🔎 What This Does

  • Takes user-entered data from Power BI as a table.
  • Converts it to JSON payload.
  • Calls Databricks Model Serving endpoint.
  • Handles various possible prediction formats:
    • single numeric predictions
    • lists of predictions
    • dictionaries of results
  • Merges predictions back into the original table.

💡 Advantages of This Method

✅ Super flexible for dynamic inputs
✅ Great for PoC demos and interactive reports
✅ Business-friendly approach—no code needed by users
✅ Predictions update automatically when inputs change


⚠️ Limitations and Considerations

  • Python scripting in Power BI requires the Python runtime installed locally.
  • Personal Access Tokens should be secured (e.g. not stored in plain text).
  • There might be latency if your model takes time to compute predictions.

🎯 Use Cases

Integrating Databricks Model Serving into Power BI opens up endless possibilities:

Stock Price Prediction
Sales Forecasting
Customer Churn Analysis
Fraud Detection
Predictive Maintenance


🚀 Conclusion

Integrating Databricks Model Serving with Power BI is a game-changer for real-time analytics. Whether you use the Python script approach or Power Query with Enter Data, you’re enabling truly interactive, predictive dashboards that empower business users.

✅ Next Steps

  • Make sure your Databricks Serving endpoint is production-ready.
  • Move sensitive tokens to secure stores like Azure Key Vault.
  • Optimize API call performance for large-scale use.
  • Explore scheduled refreshes in Power BI Service to automate insights.

Thank You,
Vivek Janakiraman

Disclaimer:
The views expressed on this blog are mine alone and do not reflect the views of my company or anyone else. All postings on this blog are provided “AS IS” with no warranties, and confers no rights.