Discourse does not support Mistral structured content responses

AI-generated summary

RGJ reported a bug where Discourse fails to handle structured content responses from the Mistral Large 4 model during post moderation. The error TypeError : no implicit conversion of Hash into String occurs because Mistral returns delta.content as a complex JSON object containing thinking and text blocks, whereas Discourse’s completion handler expects a simple string (as seen with OpenAI models). Since reasoning cannot be disabled in Mistral 4, this format is unavoidable. Falco questioned the behavior, noting that structured output appears inside the thinking block, and asked for additional log lines to confirm if the crash happened before the final response chunk. RGJ confirmed the process crashed immediately after the logged partial chunk.

In response to the issue, satonotdead suggested using LiteLLM as a proxy to normalize the API responses, describing it as a temporary hack rather than a proper fix. The issue was later addressed by sam, who shared a pull request implementing support for Mistral’s structured content. This fix aims to normalize the endpoint by extracting type: "text" chunks for the final response and handling type: "thinking" blocks separately, ensuring compatibility with the new model format.

When moderating a post the following error occurs

LlmAgentTriage.handle : TypeError : no implicit conversion of Hash into String

Discourse v2026.10.1

Model: mistral-large-4

-[ RECORD 2 ]------------+----------------------------------------------
id                       | 5
display_name             | Mistral Large 4
name                     | mistral-large-4
provider                 | mistral
tokenizer                | DiscourseAi::Tokenizer::MistralTokenizer
max_prompt_tokens        | 8000
created_at               | 2026-11-17 16:54:32.819593
updated_at               | 2026-11-17 16:54:32.819593
url                      | https://api.eu.mistral.ai/v1/chat/completions
api_key                  |
user_id                  |
enabled_chat_bot         | f
provider_params          | {"disable_native_tools": null}
vision_enabled           | f
input_cost               |
cached_input_cost        |
output_cost              |
max_output_tokens        | 2000
cache_write_cost         | 0
allowed_attachment_types | {}
ai_secret_id             | 1
vision_llm_model_id      |

When moderating a post this happens


Error responding to: /t/testing-7-17-11-2026/2437/3 in LlmAgentTriage.handle : TypeError : no implicit conversion of Hash into String


Backtrace

/var/www/discourse/plugins/discourse-ai/lib/ai_bot/playground.rb:889:in 'block in DiscourseAi::AiBot::Playground#reply_to_unlocked'
/var/www/discourse/plugins/discourse-ai/lib/agents/bot.rb:461:in 'block in DiscourseAi::Agents::Bot#reply'
/var/www/discourse/plugins/discourse-ai/lib/completions/llm.rb:381:in 'block in DiscourseAi::Completions::Llm#generate'
/var/www/discourse/plugins/discourse-ai/lib/completions/endpoints/base.rb:799:in 'block in DiscourseAi::Completions::Endpoints::Base#streaming_partial_handler'
/var/www/discourse/plugins/discourse-ai/lib/completions/endpoints/base.rb:835:in 'block (3 levels) in DiscourseAi::Completions::Endpoints::Base#streaming_response'
/var/www/discourse/plugins/discourse-ai/lib/completions/endpoints/base.rb:835:in 'Array#each'
/var/www/discourse/plugins/discourse-ai/lib/completions/endpoints/base.rb:835:in 'block (2 levels) in DiscourseAi::Completions::Endpoints::Base#streaming_response'
/var/www/discourse/plugins/discourse-ai/lib/completions/endpoints/base.rb:823:in 'Array#each'
/var/www/discourse/plugins/discourse-ai/lib/completions/endpoints/base.rb:823:in 'block in DiscourseAi::Completions::Endpoints::Base#streaming_response'
net-protocol-0.4.0/lib/net/protocol.rb:604:in 'Net::ReadAdapter#call_block'
net-protocol-0.4.0/lib/net/protocol.rb:595:in 'Net::ReadAdapter#<<'
net-protocol-0.4.0/lib/net/protocol.rb:205:in 'Net::BufferedIO#read'
net-http-0.10.0/lib/net/http/response.rb:657:in 'Net::HTTPResponse#read_chunked'
net-http-0.10.0/lib/net/http/response.rb:616:in 'block in Net::HTTPResponse#read_body_0'
net-http-0.10.0/lib/net/http/response.rb:609:in 'Net::HTTPResponse#inflater'
net-http-0.10.0/lib/net/http/response.rb:614:in 'Net::HTTPResponse#read_body_0'
net-http-0.10.0/lib/net/http/response.rb:384:in 'Net::HTTPResponse#read_body'
/var/www/discourse/plugins/discourse-ai/lib/completions/endpoints/base.rb:818:in 'DiscourseAi::Completions::Endpoints::Base#streaming_response'
/var/www/discourse/plugins/discourse-ai/lib/completions/endpoints/base.rb:571:in 'block (3 levels) in DiscourseAi::Completions::Endpoints::Base#perform_completion_request_with_retries'
net-http-0.10.0/lib/net/http.rb:2520:in 'block in Net::HTTP#transport_request'
net-http-0.10.0/lib/net/http/response.rb:341:in 'Net::HTTPResponse#reading_body'
net-http-0.10.0/lib/net/http.rb:2517:in 'Net::HTTP#transport_request'
net-http-0.10.0/lib/net/http.rb:2463:in 'Net::HTTP#request'
rack-mini-profiler-5.0.0/lib/patches/net_patches.rb:19:in 'block in Net::HTTP#request_with_mini_profiler'
rack-mini-profiler-5.0.0/lib/mini_profiler/profiling_methods.rb:51:in 'Rack::MiniProfiler::ProfilingMethods#step'
rack-mini-profiler-5.0.0/lib/patches/net_patches.rb:18:in 'Net::HTTP#request_with_mini_profiler'
/var/www/discourse/plugins/discourse-ai/lib/completions/endpoints/base.rb:522:in 'block (2 levels) in DiscourseAi::Completions::Endpoints::Base#perform_completion_request_with_retries'
net-http-0.10.0/lib/net/http.rb:1634:in 'Net::HTTP#start'
net-http-0.10.0/lib/net/http.rb:1068:in 'Net::HTTP.start'
/var/www/discourse/plugins/discourse-ai/lib/completions/endpoints/base.rb:503:in 'block in DiscourseAi::Completions::Endpoints::Base#perform_completion_request_with_retries'
:168:in 'Kernel#loop'

Logs have this


raw_response_payload | data: {"id":"bbda4b362069470e9c57d735628e0bbe","object":"chat.completion.chunk","created":1794935117,"model":"mistral-large-4","choices":[{"index":0,"delta":{"role":"assistant","content":""},"finish_reason":null}]}                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             +
                     |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    +
                     | data: {"id":"bbda4b362069470e9c57d735628e0bbe","object":"chat.completion.chunk","created":1794935117,"model":"mistral-large-4","choices":[{"index":0,"delta":{"content":[{"type":"thinking","thinking":[{"type":"text","text":"The user is asking"}],"closed":true}]},"finish_reason":null}],"p":"abcdefghijklmnopqrstuvwxyz012"} 
                     

Where OpenAI’s streaming format uses a string for delta.content:

{
  "choices": [{
    "delta": {
      "content": "The answer is..."
    }
  }]
}

Mistral Large 4 instead returns structured content blocks:

"delta": {
  "content": [
    {
      "type": "thinking",
      "thinking": [
        {
          "type": "text",
          "text": "The user is asking"
        }
      ],
      "closed": true
    }
  ]
}

It can subsequently return type: "text" blocks within the same structure. See Reasoning | Mistral Docs

Discourse cannot handle this. It should normalize the structured content in the Mistral endpoint, extracting type: "text" chunks and handling type: "thinking" separately, instead of treating it like a string.

1 like

Wait, they return the structured output inside the thinking block !?

What happens if you disable reasoning?

1 like

It is not possible to disable reasoning in Mistral 4.

HAL 9000: I'm Afraid I Can't Do That

1 like

I understand it doesn’t directly answer the initial question, but LiteLLM can be used as a proxy and it’s the solution I found in similar situations and with other models that didn’t accept or needed certain elements in the prompts sent from Discourse.

It’s more of a hack than a workaround.

Can you share the other lines? It appears that those aren’t final as "finish_reason":null

It crashed after that line, so it stopped receiving and logging the rest of the models output.

Does this work for you @RGJ

1 like