llamaIndex - ✅(Solved) Fix [Feature Request]: Mistral Azure SDK [1 pull requests, 1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
run-llama/llama_index#20667Fetched 2026-04-08 00:31:37
View on GitHub
Comments
0
Participants
1
Timeline
4
Reactions
0
Participants
Timeline (top)
labeled ×2closed ×1cross-referenced ×1

Error Message

content += content_delta │ └ [{'reference_ids': [1], 'type': 'reference'}] └ "Papa Waigo N'Diaye è un ex calciatore senegalese..."

TypeError: can only concatenate str (not "list") to str

Root Cause

Why? This because Mistral models frequently return ReferenceChunk objects during streaming (refer to Mistral Citations). The OpenAILike class assumes all delta content is a string, leading to a TypeError during stream concatenation

Fix Action

Fixed

PR fix notes

PR #20668: Rrubini/mistral azure sdk

Description (problem / solution / changelog)

Description

This is related to #20667

This PR adds native support for Mistral models deployed via Azure AI Foundry within LlamaIndex. Previously, the only way to use these models was through the OpenAILike class, which is insufficient for handling Mistral-specific features like Citations.

Problem: Mistral models frequently return ReferenceChunk objects during streaming, but the OpenAILike class assumes all delta content is a string, causing a TypeError during stream concatenation.

Solution:

  • Introduced a MistralModels Protocol to abstract model types, enabling seamless switching between standard Mistral and Azure Mistral SDKs
  • Updated helper functions (to_mistral_chunks, to_mistral_chatmessage) to accept a models parameter
  • Enhanced the MistralAI class with conditional client initialization based on provided credentials
  • All streaming methods now use dynamic model references to handle both SDK implementations

Dependencies: mistralai-azure SDK

Fixes # (issue)

New Package?

Did I fill in the tool.llamahub section in the pyproject.toml and provide a detailed README.md for my new integration or package?

  • Yes
  • No

Version Bump?

Did I bump the version in the pyproject.toml file of the package I am updating? (Except for the llama-index-core package)

  • Yes
  • No

Type of Change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Your pull-request will likely not be merged unless it is covered by some form of impactful unit testing.

  • I added new unit tests to cover this change
  • I believe this change is already covered by existing unit tests

Suggested Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added Google Colab support for the newly added notebooks.
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • I ran uv run make format; uv run make lint to appease the lint gods

Testing Note

I successfully ran the tests with the Azure SDK and the model works correctly. However, since I don't have access to the standard Mistral API key, I cannot run the complete test suite. All Azure-specific tests pass, and the implementation maintains backward compatibility with the existing Mistral API tests.

Changed files

  • llama-index-integrations/llms/llama-index-llms-mistralai/README.md (modified, +18/-0)
  • llama-index-integrations/llms/llama-index-llms-mistralai/llama_index/llms/mistralai/base.py (modified, +111/-68)
  • llama-index-integrations/llms/llama-index-llms-mistralai/pyproject.toml (modified, +2/-2)
  • llama-index-integrations/llms/llama-index-llms-mistralai/tests/test_llms_mistral.py (modified, +28/-0)

Code Example

content += content_delta
    │          └ [{'reference_ids': [1], 'type': 'reference'}]
"Papa Waigo N'Diaye è un ex calciatore senegalese..."

TypeError: can only concatenate str (not "list") to str
RAW_BUFFERClick to expand / collapse

Feature Description

Currently, the only way to use Mistral models deployed via Azure AI Foundry within LlamaIndex is through the OpenAILike class. However, this approach is insufficient when dealing with specific Mistral features such as Citations.

Why? This because Mistral models frequently return ReferenceChunk objects during streaming (refer to Mistral Citations). The OpenAILike class assumes all delta content is a string, leading to a TypeError during stream concatenation

content += content_delta
    │          └ [{'reference_ids': [1], 'type': 'reference'}]
    └ "Papa Waigo N'Diaye è un ex calciatore senegalese..."

TypeError: can only concatenate str (not "list") to str

Add native support for the Mistral Azure SDK within LlamaIndex. This new provider should:

  1. Support Azure AI Foundry authentication and endpoint structures.
  2. Implement the same streaming logic used in the base MistralAI class to correctly handle or filter ReferenceChunks.

Reason

No response

Value of Feature

No response

extent analysis

Fix Plan

To add native support for the Mistral Azure SDK within LlamaIndex, we will create a new provider class that handles Azure AI Foundry authentication and endpoint structures, as well as implements the correct streaming logic for ReferenceChunks.

Step-by-Step Solution

  • Create a new class MistralAzureProvider that inherits from the base MistralAI class.
  • Implement the __init__ method to handle Azure AI Foundry authentication and endpoint structures.
  • Override the stream method to correctly handle ReferenceChunks.
  • Add error handling for cases where ReferenceChunks are not supported.

Example Code

import requests
from mistral.azure import MistralAzure

class MistralAzureProvider:
    def __init__(self, endpoint, api_key):
        self.endpoint = endpoint
        self.api_key = api_key
        self.mistral_azure = MistralAzure(endpoint, api_key)

    def stream(self, prompt, max_tokens):
        response = self.mistral_azure.stream(prompt, max_tokens)
        content = ""
        for delta in response:
            if isinstance(delta, str):
                content += delta
            elif isinstance(delta, dict) and delta.get("type") == "reference":
                # Handle ReferenceChunk
                reference_ids = delta.get("reference_ids")
                # Filter or process ReferenceChunk as needed
                content += f"Reference: {reference_ids}"
            else:
                raise ValueError("Unsupported delta type")
        return content

Verification

To verify that the fix worked, test the MistralAzureProvider class with a sample prompt and max tokens, and check that the response correctly handles ReferenceChunks.

Extra Tips

  • Make sure to handle errors and exceptions properly, especially when dealing with external APIs and authentication.
  • Consider adding logging and monitoring to track issues and improve the overall reliability of the system.
  • Refer to the Mistral Azure SDK documentation for more information on authentication and endpoint structures.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING