Discourse does not support Mistral structured content responses

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

RGJ reports a bug in Discourse v2026.10.1 where the AI moderation feature crashes with a TypeError: no implicit conversion of Hash into String when using the mistral-large-4 model. The error occurs during LlmAgentTriage.handle when attempting to moderate a post.

The root cause is identified as an incompatibility between Discourse’s expected streaming format and Mistral Large 4’s structured response format. While OpenAI-style APIs return delta.content as a simple string, Mistral Large 4 returns delta.content as an array of structured objects. These objects contain nested data, such as thinking blocks with type "thinking" and text blocks with type "text".

Discourse currently attempts to process this entire structure as a string, leading to the type conversion error. The reporter includes backtrace logs showing the issue originates in discourse-ai/lib/completions/endpoints/base.rb within the streaming_partial_handler. The proposed fix involves updating the Mistral endpoint to normalize the structured content by extracting chunks of type "text" for standard processing and handling "thinking" blocks separately, rather than treating the entire delta content as a string. This behavior aligns with the Mistral reasoning documentation.

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.