Skip to content

[BUG] Structured output fails silently in Godot #421

@MaxKablaam

Description

@MaxKablaam

Describe the bug
When I use set_sampler_preset_json() in my script to set the model to use structured output and run the program, it immediately quits once the scene is loaded, with no error message.

To Reproduce
Steps to reproduce the behavior:

  1. Create a new scene
  2. Use the simple chat template from the docs, put set_sampler_preset_json() right before the ask()
  3. Run the scene
  4. It immediately quits with no error

Expected behavior
The runtime should not quit, and the model should give structured output.

Environment:

  • OS: MacOS
  • Godot Version: 4.6.1
  • Nobodywho Version: 8.1.0
  • LLM Model: Tested with...
    • Phi-4-mini-instruct-Q4_K_M.gguf
    • Qwen_Qwen3-0.6B-Q4_K_M.gguf
    • Qwen_Qwen3-4B-Q4_K_M.gguf
    • gemma-3-4b-it-q4_0.gguf

Additional context
Here is my script:

extends NobodyWhoChat

func _ready():
    # self.response_updated.connect(_on_response_updated)
    self.response_finished.connect(_on_response_finished)

    start_worker()

    set_sampler_preset_json()
    ask("How are you?")

func _on_response_updated(token):
    # this will print every time a new token is generated
    print(token)

func _on_response_finished(response):
    # this will print when the entire response is finished
    print(response)

Here is the output:

2026-03-12T20:46:42.583325Z  INFO get_model: nobodywho::llm: Loading model use_gpu=true gpu_layers=4294967295 model_path="/Users/eric/Workspace/llm-test/models/gemma-3-4b-it-q4_0.gguf" use_gpu_if_available=true
2026-03-12T20:46:44.239808Z  INFO get_model:model_load: nobodywho::llm: Model loaded successfully model_path="/Users/eric/Workspace/llm-test/models/gemma-3-4b-it-q4_0.gguf" use_gpu_if_available=true path="/Users/eric/Workspace/llm-test/models/gemma-3-4b-it-q4_0.gguf"
2026-03-12T20:46:44.240963Z  INFO nobodywho::llm: Initializing worker
2026-03-12T20:46:44.474019Z  INFO nobodywho::chat: Worker processing: msg=SetSamplerConfig { sampler_config: SamplerConfig { steps: [TopK { top_k: 20 }, TopP { min_keep: 1, top_p: 0.95 }, Temperature { temperature: 0.6 }, Grammar { trigger_on: None, root: "root", grammar: "# this default gbnf grammar forces valid json output\nroot   ::= object\nvalue  ::= object | array | string | number | (\"true\" | \"false\" | \"null\") ws\n\nobject ::=\n\"{\" ws (\n            string \":\" ws value\n    (\",\" ws string \":\" ws value)*\n)? \"}\" ws\n\narray  ::=\n\"[\" ws (\n            value\n    (\",\" ws value)*\n)? \"]\" ws\n\nstring ::=\n\"\\\"\" (\n    [^\"\\\\\\x7F\\x00-\\x1F] |\n    \"\\\\\" ([\"\\\\bfnrt] | \"u\" [0-9a-fA-F]{4}) # escapes\n)* \"\\\"\" ws\n\nnumber ::= (\"-\"? ([0-9] | [1-9] [0-9]{0,15})) (\".\" [0-9]+)? ([eE] [-+]? [0-9] [1-9]{0,15})? ws\n\n# Optional space: by convention, applied in this grammar after literal chars when allowed\nws ::= | \" \" | \"\\n\" [ \\t]{0,20}" }], sample_step: Some(Dist), seed: 1234 } }
2026-03-12T20:46:44.476651Z  INFO nobodywho::chat: Worker processing: msg=Ask { text: "How are you?" }
2026-03-12T20:46:44.492472Z  INFO nobodywho::chat: Worker writing until done
--- Debugging process stopped ---

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions