Discourse does not support Mistral structured content responses

סיכום מבוסס בינה מלאכותית

RGJ reports a bug in Discourse v2026.10.1 where using the mistral-large-4 model triggers a TypeError: no implicit conversion of Hash into String during AI moderation. The issue arises because Mistral returns delta.content as structured JSON objects (containing thinking and text blocks) rather than the simple string format used by OpenAI. Discourse fails to parse this structure, causing a crash when the AI agent attempts to process the response. RGJ notes that reasoning cannot be disabled in Mistral 4, making this a critical integration gap.

Falco questions if disabling reasoning is a potential workaround, but RGJ confirms it is not an option for this model, humorously attaching a “HAL 9000” meme to illustrate the inability to change the behavior. satonotdead suggests using LiteLLM as a proxy to normalize the API response format, although they acknowledge it is a “hack” rather than a proper solution.

Regarding the logs provided by RGJ, Falco asks for additional lines since the snippet ends with finish_reason: null, suggesting it might be an intermediate chunk. RGJ clarifies that the application crashed immediately after that line, preventing any further output from being logged or received.

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

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

What happens if you disable reasoning?

It is not possible to disable reasoning in Mistral 4.

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

לייק 1

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.