[GH-ISSUE #3054] [Issue]: Negation word in a comma-separated prompt clause sweeps all following positive descriptors into the negative prompt #1622

Closed
opened 2026-10-21 05:40:56 +07:00 by bsakaguchi · 2 comments
Owner

Originally created by @kolacheee on GitHub (Jun 29, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/3054

Originally assigned to: @SpicyMarinara on GitHub.

What's wrong

When an image prompt (or the user's positive-prompt field) contains a comma-separated clause that starts with a negation word (no / avoid / without / exclude / "do not include"), the compiler grabs the entire rest of the clause as the thing to negate. Everything after that word — which the user or the LLM meant as positive detail — gets moved into the negative prompt and actively excluded from the image.

Concrete examples:

  • no glasses, red hair -> the negative prompt ends up containing glasses, red hair, so the requested red hair is excluded.
  • A woman, no makeup, holding flowers, smiling -> the negative prompt becomes makeup, holding flowers, smiling, and the positive prompt keeps only A woman. The flowers and the smile are thrown away.

This silently inverts user intent and is reachable from the normal selfie, portrait, and avatar generation paths, because LLM-authored descriptions frequently contain phrases like no makeup, natural light.

How to reproduce (try it yourself)

  1. Use a character/persona whose style profile is a built-in natural-mode (realistic / photorealistic / z-image-turbo) or tagged (anime / danbooru) profile.
  2. Trigger a selfie/portrait generation whose prompt is A woman, no makeup, holding flowers, smiling (or set the user positive field to no glasses, red hair).
  3. This runs through compileImagePrompt.

You'll see: the negative prompt contains makeup, holding flowers, smiling (the flowers and smile are excluded); the positive prompt keeps only A woman plus profile tags. For no glasses, red hair, the negative contains glasses, red hair and the red hair is dropped.

Expected: only the directly-negated term is excluded (makeup / glasses); the trailing descriptors (holding flowers, smiling, red hair) remain in the positive prompt.

Where it is

packages/shared/src/utils/image-prompt-compiler.ts:

  • extractNegativeFragment line 569 — clean.match(/^(?:avoid|no|without|exclude|do not include|don't include)\s+(.+)$/i); the greedy unbounded (.+)$ captures everything after the negation word to end of string.
  • distillTaggedPromptSource lines 231-237 — fans the captured string out on [,;], pushing every piece as avoid <item>.
  • Natural-mode splitter lines 204-208 — /\n+|,(?=\s*(?:avoid|no|without)\b)/i only splits the comma before a negation word, so the negation word stays attached to all following non-negation commas.
  • compileImagePrompt positive loop lines 88-91 — runs each fragment through extractNegativeFragment then splitNegativePromptItems (split on [,;]).

Caller entry points: packages/server/src/routes/generate.routes.ts:9523 (selfie), :8400 (portrait); packages/server/src/routes/characters.routes.ts:333,400 (avatar).

What's happening

extractNegativeFragment's capture group is greedy and unbounded, so for no makeup, holding flowers, smiling it captures makeup, holding flowers, smiling instead of just makeup. Both consumption sites then comma-split that captured string into multiple negatives. The sentence/clause splitters deliberately keep the leading negation word bound to its trailing comma list, so any positive descriptor that follows a negated term in the same clause-run is swept into the negative prompt.

Suggested fix

Bound the negation to one comma-clause AND route the trailing terms back onto the positive path (do not merely stop negating them — a naive ([^,;]+) change alone silently drops them, which is a different bug):

  1. extractNegativeFragment (line 569): change the greedy capture to stop at the first comma/semicolon:
    const match = clean.match(/^(?:avoid|no|without|exclude|do not include|don't include)\s+([^,;]+)/i);
    Legitimate multi-word negatives (no extra fingers, without makeup) have no internal comma, so they still negate as one term.

  2. Route the post-negation remainder to the positive path at both consumption sites:

    • Natural path (around line 198-206): in the normalize chain, insert a newline after a leading-negation single term, e.g. .replace(/((?:^|[\n,])\s*(?:avoid|no|without|exclude|do not include|don't include)\s+[^,;\n]+),/gi, "$1\n"), so no makeup, holding flowers, smiling becomes ...no makeup\nholding flowers, smiling and the trailing terms flow to positives via the normal split.
    • distillTaggedPromptSource (lines 231-238): on a negation match, push avoid <firstClause> only, strip that leading negation clause from sentence, and fall through (do NOT continue) to the existing per-item loop (lines 262-275), which already classifies the remaining items correctly. This keeps red hair positive while negating glasses.

Regression avoided: option (a) by itself (just bounding the regex) converts the inversion into silent data-loss because neither call site re-adds the trailing terms to the positive list; the corrected fix re-routes them. The background subject tag no people (image-style-profiles.ts:91) still negates correctly (no comma), userNegative/hardNegative/negativePrompt never touch the positive path, and the server compiler is a thin re-export of this shared helper, so all providers and callers benefit. No tests exist for this file.


AI-investigated against v2.0.6; cited lines read and confirmed. Please verify before fixing.

Originally created by @kolacheee on GitHub (Jun 29, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/3054 Originally assigned to: @SpicyMarinara on GitHub. **What's wrong** When an image prompt (or the user's positive-prompt field) contains a comma-separated clause that starts with a negation word (no / avoid / without / exclude / "do not include"), the compiler grabs the *entire rest of the clause* as the thing to negate. Everything after that word — which the user or the LLM meant as positive detail — gets moved into the negative prompt and actively excluded from the image. Concrete examples: - `no glasses, red hair` -> the negative prompt ends up containing `glasses, red hair`, so the requested red hair is excluded. - `A woman, no makeup, holding flowers, smiling` -> the negative prompt becomes `makeup, holding flowers, smiling`, and the positive prompt keeps only `A woman`. The flowers and the smile are thrown away. This silently inverts user intent and is reachable from the normal selfie, portrait, and avatar generation paths, because LLM-authored descriptions frequently contain phrases like `no makeup, natural light`. **How to reproduce (try it yourself)** 1. Use a character/persona whose style profile is a built-in natural-mode (realistic / photorealistic / z-image-turbo) or tagged (anime / danbooru) profile. 2. Trigger a selfie/portrait generation whose prompt is `A woman, no makeup, holding flowers, smiling` (or set the user positive field to `no glasses, red hair`). 3. This runs through `compileImagePrompt`. You'll see: the negative prompt contains `makeup, holding flowers, smiling` (the flowers and smile are excluded); the positive prompt keeps only `A woman` plus profile tags. For `no glasses, red hair`, the negative contains `glasses, red hair` and the red hair is dropped. Expected: only the directly-negated term is excluded (`makeup` / `glasses`); the trailing descriptors (`holding flowers`, `smiling`, `red hair`) remain in the positive prompt. **Where it is** `packages/shared/src/utils/image-prompt-compiler.ts`: - `extractNegativeFragment` line 569 — `clean.match(/^(?:avoid|no|without|exclude|do not include|don't include)\s+(.+)$/i)`; the greedy unbounded `(.+)$` captures everything after the negation word to end of string. - `distillTaggedPromptSource` lines 231-237 — fans the captured string out on `[,;]`, pushing every piece as `avoid <item>`. - Natural-mode splitter lines 204-208 — `/\n+|,(?=\s*(?:avoid|no|without)\b)/i` only splits the comma *before* a negation word, so the negation word stays attached to all following non-negation commas. - `compileImagePrompt` positive loop lines 88-91 — runs each fragment through `extractNegativeFragment` then `splitNegativePromptItems` (split on `[,;]`). Caller entry points: `packages/server/src/routes/generate.routes.ts:9523` (selfie), `:8400` (portrait); `packages/server/src/routes/characters.routes.ts:333,400` (avatar). **What's happening** `extractNegativeFragment`'s capture group is greedy and unbounded, so for `no makeup, holding flowers, smiling` it captures `makeup, holding flowers, smiling` instead of just `makeup`. Both consumption sites then comma-split that captured string into multiple negatives. The sentence/clause splitters deliberately keep the leading negation word bound to its trailing comma list, so any positive descriptor that follows a negated term in the same clause-run is swept into the negative prompt. **Suggested fix** Bound the negation to one comma-clause AND route the trailing terms back onto the positive path (do not merely stop negating them — a naive `([^,;]+)` change alone silently *drops* them, which is a different bug): 1. `extractNegativeFragment` (line 569): change the greedy capture to stop at the first comma/semicolon: `const match = clean.match(/^(?:avoid|no|without|exclude|do not include|don't include)\s+([^,;]+)/i);` Legitimate multi-word negatives (`no extra fingers`, `without makeup`) have no internal comma, so they still negate as one term. 2. Route the post-negation remainder to the positive path at both consumption sites: - Natural path (around line 198-206): in the normalize chain, insert a newline after a leading-negation single term, e.g. `.replace(/((?:^|[\n,])\s*(?:avoid|no|without|exclude|do not include|don't include)\s+[^,;\n]+),/gi, "$1\n")`, so `no makeup, holding flowers, smiling` becomes `...no makeup\nholding flowers, smiling` and the trailing terms flow to positives via the normal split. - `distillTaggedPromptSource` (lines 231-238): on a negation match, push `avoid <firstClause>` only, strip that leading negation clause from `sentence`, and fall through (do NOT `continue`) to the existing per-item loop (lines 262-275), which already classifies the remaining items correctly. This keeps `red hair` positive while negating `glasses`. Regression avoided: option (a) by itself (just bounding the regex) converts the inversion into silent data-loss because neither call site re-adds the trailing terms to the positive list; the corrected fix re-routes them. The background subject tag `no people` (image-style-profiles.ts:91) still negates correctly (no comma), `userNegative`/`hardNegative`/`negativePrompt` never touch the positive path, and the server compiler is a thin re-export of this shared helper, so all providers and callers benefit. No tests exist for this file. --- *AI-investigated against v2.0.6; cited lines read and confirmed. Please verify before fixing.*
Author
Owner

@SpicyMarinara commented on GitHub (Jun 29, 2026):

Claiming this for the current staging sweep in draft PR #3064: https://github.com/Pasta-Devs/Marinara-Engine/pull/3064

<!-- gh-comment-id:4835428372 --> @SpicyMarinara commented on GitHub (Jun 29, 2026): Claiming this for the current staging sweep in draft PR #3064: https://github.com/Pasta-Devs/Marinara-Engine/pull/3064
Author
Owner

@SpicyMarinara commented on GitHub (Jun 29, 2026):

Fixed in PR #3064 on branch codex/issue-sweep-3054-3063 (commit 3ae8ca37). Closing this issue as addressed; the PR remains open for staging review/merge.

<!-- gh-comment-id:4835577684 --> @SpicyMarinara commented on GitHub (Jun 29, 2026): Fixed in PR #3064 on branch `codex/issue-sweep-3054-3063` (commit 3ae8ca37). Closing this issue as addressed; the PR remains open for staging review/merge.
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#1622
No description provided.