Running into "ValueError: Invalid connection string format"

James 125 Reputation points
2025-04-02T23:07:59.2066667+00:00

Im doing the Microsoft Learn Module: https://learn.microsoft.com/en-us/azure/ai-foundry/tutorials/copilot-sdk-build-rag?ns-enrollment-type=Collection&ns-enrollment-id=pzxuztm2qzp3y

and running into the following error: PS C:\Users\jjhpe...python create_search_index.py

INFO:azure.identity._credentials.environment:No environment configuration found.

INFO:azure.identity._credentials.managed_identity:ManagedIdentityCredential will use IMDS

Traceback (most recent call last):

File "C:\Users\jjhpe...create_search_index.py", line 34, in <module>

project = AIProjectClient.from_connection_string(

          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File "C:\Users\jjhpe...\ChatAppProject.venv\Lib\site-packages\azure\ai\projects_patch.py", line 242, in from_connection_string

raise ValueError("Invalid connection string format")

ValueError: Invalid connection string format

--

Sorry I am very new to this with minimal technical experience but stuck on how to move forward with the learning module.

Thank you for any guidance.

Azure AI Search
Azure AI Search
An Azure search service with built-in artificial intelligence capabilities that enrich information to help identify and explore relevant content at scale.
1,339 questions
{count} votes

Accepted answer
  1. Prabhavathi Manchala 2,315 Reputation points Microsoft External Staff Moderator
    2025-04-03T01:07:37.47+00:00

    Hi James,

    The error ValueError: Invalid connection string format means the connection string in create_search_index.py is incorrect or not properly formatted. This could happen if the connection string is missing, incorrect, or copied with extra spaces or missing parts. It may also be caused by using the wrong environment variable. Double-check the connection string in the Azure portal and ensure it's set correctly.

    • Please check your connection string by going to the Azure Portal -> navigating to your AI Project (Azure AI Services or AI Foundry), find the correct connection string and ensure it follows the proper format.
    endpoint=https://yourproject.region.ai.azure.com/;key=your-key  
    
    • Go to Azure Storage Account → Access Keys → Connection Strings in the Azure portal and copy the correct connection string. Then, update create_search_index.py by replacing your-connection-string-here with the correct connection string.
    project = AIProjectClient.from_connection_string("your-connection-string-here")  
    
    • Check and set the environment variable in PowerShell by running
    echo $Env:AZURE_AI_CONNECTION_STRING  
    

    If it's empty/wrong, set it again

    $Env:AZURE_AI_CONNECTION_STRING = "your-connection-string-here"  
    

    Please check below documents to configure environment variables.

    https://learn.microsoft.com/en-us/azure/ai-foundry/tutorials/copilot-sdk-create-resources?tabs=windows#configure-environment-variables

    https://learn.microsoft.com/en-us/azure/ai-foundry/tutorials/copilot-sdk-create-resources?tabs=windows#configure-environment-variables

    Please accept as "Yes" if the answer provided is useful, so that you can help others in the community looking for remediation for similar issues.

    Let me know if you have any further Queries.

    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.