Microsoft Fabric Updates Blog

Chat your data in Microsoft Fabric with Semantic Kernel

Using Microsoft Fabric’s Lakehouse we can manage different data sources. Today Microsoft Copilot is very popular, and we hope that Microsoft Fabric can become an indispensable part of enterprise data management and make it easier for enterprise data to connect with LLM. This blog will combines data engineering and data science perspectives to construct Copilot tools based on business data in Microsoft Fabric.

Semantic Kernel

The framework for LLM-based applications is mainly chosen between LangChain and Semantic Kernel. I personally prefer Semantic Kernel to better control the connection between Prompt and Code. And for a multi-programming language application scenario, Semantic Kernel is undoubtedly the best choice. Not only .NET, but also Python and Java are available, allowing more developers and enterprises to use existing technologies to seamlessly enter Copilot applications.

Chat with your structured enterprise data

How to let LLM communication with data? For enterprises, there is unstructured data and structured data. We have many solutions for unstructured data. Through Embedding or Fine-tune, we can quickly complete Copilot applications for unstructured data. For structured data, perhaps we need some traditional techniques. In past scenarios, we can extract and analyze data through Python’s Library(Panda, Spark, Matplotlib, etc) and T-SQL. So we can also use Prompt to help us generate sentences for structured data to complete chat scenarios based on structured data. GPT-4 has very powerful code generation capabilities. We can make good use of Prompt’s role capabilities to enable GPT-4’s data language generation for structured data.

This is the application architecture diagram

Let’s Chat with your enterprise data

A. Choose Data Engineering, create lake house and upload csv and your data prompt to this lake house

# create lake house, give a name ‘mydatasource’ , and upload files from (MSFabricwithSKSamples/skills at main · kinfey/MSFabricwithSKSamples ( and (MSFabricwithSKSamples/datasets at main · kinfey/MSFabricwithSKSamples (

# load sales.csv’s data to table

# check your Lakehouse

B. Choose Data Science, create Notebook

# sync Lakehouse to your Data Science environment

# using pip install semantic-kernel in Your Notebook

! pip install semantic-kernel

# import library

import semantic_kernel as sk
from import AzureChatCompletion

# init your semantic-kernel, including

kernel = sk.Kernel()

deployment = 'Your Azure OpenAI Service GPT-4-32k model deployment name'
api_key = 'Your Azure OpenAI Service API Key'
endpoint = 'Your Azure OpenAI Service Endpoint'

kernel.add_chat_service("chat", AzureChatCompletion(deployment, endpoint, api_key))

base_skills_directory = '/lakehouse/default/Files/skills'

skills = {
**kernel.import_semantic_skill_from_directory(base_skills_directory , "dataskill"),

csv_skill = skills["csv"]
pysql_skill = skills["spark"]

C. Chat with your csv data under Panda

import pandas as pd
df = pd.read_csv("/lakehouse/default/Files/csv/ProductList.csv")

You can now manage your CSV data in Copilot Chat

Data statistics scene

panda_context_variables = sk.ContextVariables(variables={
"question": "Generate a bar chart to list Product Type and display the number of products owned by the corresponding Product Type"
panda_result = await csv_skill.invoke_async(variables=panda_context_variables )
pandasql = panda_result .result.replace("\\n","").replace("\\n\\n", "")

Query data scenarios

context_variables = sk.ContextVariables(variables={
"question": "Find Product Type belonging to Car audio and display them as table "
result = await csv_skill.invoke_async(variables=context_variables)
sql = result.result.replace("\\n","").replace("\\n\\n", "")

D. Chat with your csv data under Spark

from pyspark.context import SparkContext
from pyspark.sql.session import SparkSession
from pyspark.sql.types import *
from pyspark.sql.functions import *
df ='Files/csv/sales.csv',

You can now manage your Spark data in Copilot Chat

sparksql_context_variables = sk.ContextVariables(variables={
"question": "Search OrderDate on '2019-07-01' and counts SalesOrderLineNumber"
sparksql_result = await pysql_skill.invoke_async(variables=sparksql_context_variables )
sparksql = sparksql_result .result.replace("\n","")

E. Chat with your table under T-SQL

You can now generative your T-SQL in Copilot Chat

sql_context_variables = sk.ContextVariables(variables={
"datasource": "mydatasource",
"question": "Count the total Quantity of the Item column in Sales for Road-150 Red, 44"
sql_result = await sql_skill.invoke_async(variables=sql_context_variables)
sql_result.result.replace("\n"," ")

Here you need to manually generate a row of generated T-SQL for execution, such as

SELECT SUM(Quantity)  FROM mydatasource.Sales  WHERE Item = 'Road-150 Red, 44'

Through the above steps, Semantic Kernel has opened up the connection between enterprise data and large models in Microsoft Fabric. Let LLM better serve our enterprise intelligence. If you are interested in this content, you can download the complete example from my GitHub repo ( and give me more feedback on the issue

Related blog posts

Chat your data in Microsoft Fabric with Semantic Kernel

November 29, 2023 by Markus Cozowicz

Semantic Link adds support for the recently released OneLake integrated semantic models! You can now directly access data using your semantic model’s name via OneLake using the read_table function and the new mode parameter set to onelake. This approach ensures that no load is placed on Analysis Services, enabling efficient data retrieval and avoids putting … Continue reading “Semantic Link: OneLake integrated Semantic Models”

November 18, 2023 by Markus Cozowicz

Great Expectations Open Source(GX OSS) is a popular Python library that provides a framework for describing and validating the acceptable state of data. It helps data engineers and data scientists ensure that their data meets specific quality standards before using it for analysis, machine learning, or other data-driven tasks. With the recent integration of Microsoft … Continue reading “Semantic Link: Data validation using Great Expectations”