Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Join us at FabCon Vienna from September 15-18, 2025, for the ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM. Get registered

Reply
DiKi-I
Post Patron
Post Patron

user data function in fabric

Hi I'm trying to run UDF funtion and integarting it with azure open ai.

I'm getting the  below error during invocation can someone please help?


{
"functionName": "AISuggestion",
"invocationId": "00000000-0000-0000-0000-000000000000",
"status": "Failed",
"errors": [
{
"errorCode": "WorkloadException",
"subErrorCode": "NotFound",
"message": "User data function: 'AISuggestion' invocation failed."
}
]
}



My code
------------------------------------------------------------------------------------------

import fabric.functions as fn
import logging
import openai

udf = fn.UserDataFunctions()

@udf.connection(argName="sqlDB", alias="MyFabricSQLDB")
@udf.function()
def AISuggestion(sqlDB: fn.FabricSqlConnection, company: str) -> str:
    try:
        logging.info('Triggering AISuggestion function.')

        # Connect to SQL
        try:
            connection = sqlDB.connect()
            cursor = connection.cursor()
        except Exception as sql_conn_err:
            return f"SQL connection failed: {str(sql_conn_err)}"

        # Read company info
        try:
            cursor.execute("SELECT * FROM [dbo].[CompanyStatus] WHERE Company = ?", company)
            record = cursor.fetchone()

            if not record:
                return f"No record found for company: {company}"

            customer_name = record[0]
            last_comment = record[10]
        except Exception as query_err:
            return f"Error fetching company data: {str(query_err)}"

        # OpenAI Prompt
        prompt = (
            "Respond with a short plan that is under 240 characters: I work at Contoso Outdoors, "
            "and we collaborate with influencers by offering them offers for custom designed bikes. "
            f"Pretend we want to collab with the following influencer: {customer_name} from company: {company}. "
            f"Here's a comment about their latest feedback: {last_comment}."
        )

        # Call Azure OpenAI
        try:
            deployment = "gpt-35-turbo"  # or gpt-35-turbo
            openai_client = openai.AzureOpenAI(
                api_key='xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
                api_version="2025-01-01-preview",
            )

            response = openai_client.chat.completions.create(
                model=deployment,
                messages=[
                    {"role": "user", "content": prompt}
                ]
            )
            result = response.choices[0].message.content
        except Exception as ai_err:
            return f"OpenAI call failed: {str(ai_err)}"

        # Write result to SQL
        try:
            cursor.execute("SELECT * FROM [dbo].[AISuggestions] WHERE Company = ?", company)

            if cursor.fetchone():
                update_query = "UPDATE [dbo].[AISuggestions] SET [AI_suggestion] = ? WHERE [Company] = ?;"
                cursor.execute(update_query, (result, company))
            else:
                insert_query = "INSERT INTO [dbo].[AISuggestions] (Name, Company, AI_suggestion) VALUES (?, ?, ?);"
                cursor.execute(insert_query, (customer_name, company, result))

            connection.commit()
        except Exception as sql_write_err:
            return f"SQL insert/update failed: {str(sql_write_err)}"
        finally:
            cursor.close()
            connection.close()

        return f"Successfully generated suggestion for {customer_name} from {company}."

    except Exception as general_err:
        return f"Unhandled error: {str(general_err)}"



1 ACCEPTED SOLUTION

Hi @DiKi-I ,

If you still face the issue then please consider raising a support ticket for further assistance.

 

To raise a support ticket for Fabric and Power BI, kindly follow the steps outlined in the following guide: How to create a Fabric and Power BI Support ticket - Power BI | Microsoft Learn

 

Thank You.

 

View solution in original post

13 REPLIES 13
V-yubandi-msft
Community Support
Community Support

Hi @DiKi-I ,

May I ask if you have resolved this issue? If so, please mark the helpful reply and accept it as the solution. This will be helpful for other community members who have similar problems to solve it faster.

 

Thank you.

still getting the same error.

Hi @DiKi-I ,

If you still face the issue then please consider raising a support ticket for further assistance.

 

To raise a support ticket for Fabric and Power BI, kindly follow the steps outlined in the following guide: How to create a Fabric and Power BI Support ticket - Power BI | Microsoft Learn

 

Thank You.

 

V-yubandi-msft
Community Support
Community Support

Hi @DiKi-I ,

Thank you for your valuable inputs, @burakkaragoz  you’ve highlighted the key points perfectly. To provide further clarity, I’d like to elaborate on a few aspects that might help resolve the issue.

 

The WorkloadException with the NotFound sub error for your AISuggestion UDF indicates that the function isn’t recognized or isn’t available in the environment where it’s being called. Since your UDFs are running fine, but you're encountering issues specifically with Azure OpenAI integration, it likely involves deployment challenges, environment settings, or restrictions on external API calls.

Key Considerations:

  1. According to Microsoft Fabric documentation, UDF are still in preview as of May 2025.
  2. This can result in inconsistent deployment, limited availability in certain tenants, or restrictions on external HTTP calls (such as calls to Azure OpenAI) in secured environments.

FYI: Connect to data sources - Fabric User data functions (Preview) - Microsoft Fabric | Microsoft Learn

 

If my response resolved your query, kindly mark it as the Accepted Solution to assist others. Additionally, I would be grateful for a 'Kudos' if you found my response helpful.

DiKi-I
Post Patron
Post Patron

I'm getting workload exception.

{
"functionName": "AISuggestion",
"invocationId": "00000000-0000-0000-0000-000000000000",
"status": "Failed",
"errors": [
{
"errorCode": "WorkloadException",
"subErrorCode": "NotFound",
"message": "User data function: 'AISuggestion' invocation failed."
}
]
}

Looks like the error is saying the function AISuggestion couldn't be found or isn't available in the current context. This might happen if:

  • The function isn't deployed or registered properly in your environment.
  • You're calling it from a workspace or context where it's not accessible.
  • There's a typo or mismatch in the function name.

I'd suggest double-checking the function name and making sure it's available in the environment you're running this from. Also, if this is a custom function, make sure it's published and accessible to the workspace you're using.

burakkaragoz
Resident Rockstar
Resident Rockstar

Hi @DiKi-I ,

 

Thanks for raising this – there’s been some confusion around User Data Functions in Fabric, especially since they’re still in preview and not fully rolled out in all environments.

A few things to check:

  1. Feature Availability

    • Make sure your workspace is on a supported Fabric capacity (F64 or higher).
    • UDFs are still in private preview for some tenants, so they might not appear in the UI by default.
  2. Enable the UI Option (Workaround)

    • Try appending this to your Fabric URL and refresh the page:
     &ArtifactFunctionSet=1
    • This sometimes forces the UI to show the “User Data Function” option under “New Item”.
  3. Use Visual Studio Code (Optional)

    • You can also create and manage UDFs using the Microsoft Fabric VS Code extension, which gives more control and visibility.
  4. Known Issues

    • There’s a known issue where UDFs don’t show up in the pipeline function activity pane. Microsoft is working on it [1].

Let me know if you’re trying to use UDFs for a specific use case (e.g., calling APIs, transforming data, etc.) – I can help tailor the setup.


If my response resolved your query, kindly mark it as the Accepted Solution to assist others. Additionally, I would be grateful for a 'Kudos' if you found my response helpful.

 


References

I'm able to run udf its just that when I'm testing it with openai its not working.

Good to hear that the UDF itself is running. Regarding the issue with OpenAI, here are a few things to check:

1. Network Access

  • Make sure your UDF environment has outbound internet access. Some Fabric environments (especially in secured or restricted tenants) might block external HTTP calls.

2. Authentication

  • If you're calling OpenAI’s API, ensure you're passing the correct API key in the header:
  Authorization: Bearer YOUR_API_KEY

3. Timeouts and Payload

  • Keep the payload small for testing. Some environments have strict timeout limits for external calls.
  • Try a simple prompt first to validate the connection.

4. Error Details

  • If you’re getting a specific error message or status code, feel free to share it here. That’ll help narrow it down quickly.
thetom88
Frequent Visitor

Hello, I'm facing the exact same problem since yesterday.

The really curious behaviour is that yesterday I've published the function and got the same error. Today I re-run the function and it get executed correctly. I made a couple of changes, re-published and again the error is being raised.

 

Yes, I'm basically doing something very similar to what your function is doing, I'm not working with SQL ATM. Looking at the code you're trying to re-create the example from transanalytical task flows.

Yes, I'm using the udf example with the openai. But it doesn't seem to work. I will try again with some simple use cases.

are you calling openai from udf?

Helpful resources

Announcements
May FBC25 Carousel

Fabric Monthly Update - May 2025

Check out the May 2025 Fabric update to learn about new features.

May 2025 Monthly Update

Fabric Community Update - May 2025

Find out what's new and trending in the Fabric community.