[GH-ISSUE #4597] [Issue]: Noodler post creation fails with "expected object, received array" ZodError #2508

Closed
opened 2026-10-21 05:49:13 +07:00 by bsakaguchi · 3 comments
Owner

Originally created by @MetzeVanDeus on GitHub (Aug 4, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/4597

Originally assigned to: @Gunterlie on GitHub.

Summary

Noodler post creation consistently fails with ZodError: Expected object, received array regardless of model, context, or retry attempts. The LLM returns a JSON array [{title, content}] even though the system prompt explicitly instructs "Return one JSON object."

Expected behavior

When generating a Noodler post, the response should be parsed successfully and the post saved to the database. The Noodler should appear on the creator's page without errors.

Actual behavior

The Noodler post creation fails with:

ZodError: [
  {
    "code": "invalid_type",
    "expected": "object",
    "received": "array",
    "path": [],
    "message": "Expected object, received array"
  }
]

The LLM returns [{ "title": "...", "content": "..." }] (array with one object) instead of { "title": "...", "content": "..." } (plain object). This happens on the first attempt and persists even after the correction prompt ("Return exactly one object with title and content only").

Steps to reproduce

  1. Create a Noodler account
  2. Click "Generate post" (manual run-now)
  3. Observe the ZodError in the server logs
  4. The correction prompt fires (attempt 2) but the model returns the same array format
  5. Post creation fails

Environment

  • Marinara Engine version: v2.4.1, build cab61fc088, staging branch
  • Install type: other (Windows start.bat / launcher exe)
  • OS + version: Windows 11
  • Browser or app shell: Chromium / launcher
  • Model used: KoboldCPP/Gemma4-12B-QAT-Uncensored-HauhauCS-Balanced-Q4_K_M
  • API provider: KoboldCPP (local)

Logs, screenshots, or video

Server log:

[ERROR] ZodError: [
  {
    "code": "invalid_type",
    "expected": "object",
    "received": "array",
    "path": [],
    "message": "Expected object, received array"
  }
]
    at ZodEffects.parse
    at parseNoodlerPost (noodle-noodler-generation.service.js:111:45)
    at generateNoodlerPost (noodle-noodler-generation.service.js:182:21)
    at async generateAndApplyNoodlerPost (noodle-noodler-post.operation.js:19:20)

Generation log (model response):

{
  "response_format": {"type": "json_object"}
}

Model returns:

[{
  "title": "The Luxury of Silence",
  "content": "Most people mistake activity for progress..."
}]

The system prompt includes: "Return one JSON object with title and content only." — but the model wraps it in an array anyway.

Additional context

This affects local LLM models (Ollama, KoboldCPP, LM Studio) that don't fully respect the {"type": "json_object"} response format parameter. The model interprets it as "return JSON" rather than "return a JSON object type."
I've developed a fix locally — will open a PR once the issue is acknowledged
The fix is a small guard in parseNoodlerPost() that unwraps single-element arrays before Zod validation:

// packages/server/src/services/noodle/noodle-noodler-generation.service.ts
function parseNoodlerPost(content: string) {
  const parsed = parseGameJsonish(content);
  if (Array.isArray(parsed)) {
    const target = parsed.length > 0 ? parsed[0] : {};
    return noodleGeneratedNoodlerPostSchema.parse(target);
  }
  return noodleGeneratedNoodlerPostSchema.parse(parsed);
}

This is a minimal, targeted fix that handles the case at the parsing layer regardless of what the model returns.

Template check

Please uncheck (untick) the box below before submitting so we know you read the template. It is intentionally pre-checked:

  • I DID NOT read this template and provide the requested details.
Originally created by @MetzeVanDeus on GitHub (Aug 4, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/4597 Originally assigned to: @Gunterlie on GitHub. ## Summary Noodler post creation consistently fails with `ZodError: Expected object, received array` regardless of model, context, or retry attempts. The LLM returns a JSON array `[{title, content}]` even though the system prompt explicitly instructs "Return one JSON object." ## Expected behavior When generating a Noodler post, the response should be parsed successfully and the post saved to the database. The Noodler should appear on the creator's page without errors. ## Actual behavior The Noodler post creation fails with: ``` ZodError: [ { "code": "invalid_type", "expected": "object", "received": "array", "path": [], "message": "Expected object, received array" } ] ``` The LLM returns `[{ "title": "...", "content": "..." }]` (array with one object) instead of `{ "title": "...", "content": "..." }` (plain object). This happens on the first attempt and persists even after the correction prompt ("Return exactly one object with title and content only"). ## Steps to reproduce 1. Create a Noodler account 2. Click "Generate post" (manual run-now) 3. Observe the ZodError in the server logs 4. The correction prompt fires (attempt 2) but the model returns the same array format 5. Post creation fails ## Environment - Marinara Engine version: v2.4.1, build cab61fc0884d, staging branch - Install type: other (Windows start.bat / launcher exe) - OS + version: Windows 11 - Browser or app shell: Chromium / launcher - Model used: KoboldCPP/Gemma4-12B-QAT-Uncensored-HauhauCS-Balanced-Q4_K_M - API provider: KoboldCPP (local) ## Logs, screenshots, or video **Server log:** ``` [ERROR] ZodError: [ { "code": "invalid_type", "expected": "object", "received": "array", "path": [], "message": "Expected object, received array" } ] at ZodEffects.parse at parseNoodlerPost (noodle-noodler-generation.service.js:111:45) at generateNoodlerPost (noodle-noodler-generation.service.js:182:21) at async generateAndApplyNoodlerPost (noodle-noodler-post.operation.js:19:20) ``` **Generation log (model response):** ```json { "response_format": {"type": "json_object"} } ``` Model returns: ```json [{ "title": "The Luxury of Silence", "content": "Most people mistake activity for progress..." }] ``` The system prompt includes: "Return one JSON object with title and content only." — but the model wraps it in an array anyway. ## Additional context This affects local LLM models (Ollama, KoboldCPP, LM Studio) that don't fully respect the `{"type": "json_object"}` response format parameter. The model interprets it as "return JSON" rather than "return a JSON object type." I've developed a fix locally — will open a PR once the issue is acknowledged The fix is a small guard in `parseNoodlerPost()` that unwraps single-element arrays before Zod validation: ```typescript // packages/server/src/services/noodle/noodle-noodler-generation.service.ts function parseNoodlerPost(content: string) { const parsed = parseGameJsonish(content); if (Array.isArray(parsed)) { const target = parsed.length > 0 ? parsed[0] : {}; return noodleGeneratedNoodlerPostSchema.parse(target); } return noodleGeneratedNoodlerPostSchema.parse(parsed); } ``` This is a minimal, targeted fix that handles the case at the parsing layer regardless of what the model returns. ## Template check Please **uncheck (untick)** the box below before submitting so we know you read the template. It is intentionally pre-checked: - [ ] I DID NOT read this template and provide the requested details.
bsakaguchi 2026-10-21 05:49:13 +07:00
Author
Owner

@SpicyMarinara commented on GitHub (Aug 4, 2026):

@Gunterlie

<!-- gh-comment-id:5184060664 --> @SpicyMarinara commented on GitHub (Aug 4, 2026): @Gunterlie
Author
Owner

@Gunterlie commented on GitHub (Aug 4, 2026):

@MetzeVanDeus Yes, make the PR :)

<!-- gh-comment-id:5184095546 --> @Gunterlie commented on GitHub (Aug 4, 2026): @MetzeVanDeus Yes, make the PR :)
Author
Owner

@SpicyMarinara commented on GitHub (Aug 4, 2026):

Awesome, thank you for the PR!

<!-- gh-comment-id:5184225064 --> @SpicyMarinara commented on GitHub (Aug 4, 2026): Awesome, thank you for the PR!
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Pasta-Devs/Marinara-Engine#2508
No description provided.