{"record":{"id":"75767e7616092435","repo":"sgl-project/sglang","slug":"negative-prompt-should-be-the-same-type-to-prom","errorCode":null,"errorMessage":"`negative_prompt` should be the same type to `prompt`, but got {type(negative_prompt)} != {type(prompt)}.","messagePattern":"`negative_prompt` should be the same type to `prompt`, but got (.+?) != (.+?)\\.","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"python/sglang/multimodal_gen/runtime/pipelines_core/stages/model_specific_stages/glm_image.py","lineNumber":1027,"sourceCode":"            prompt_embeds = self._get_glyph_embeds(\n                prompt, max_sequence_length, device, dtype\n            )\n\n        seq_len = prompt_embeds.size(1)\n        prompt_embeds = prompt_embeds.repeat(1, 1, 1)\n        prompt_embeds = prompt_embeds.reshape(1, seq_len, -1)\n\n        negative_prompt_embeds = None\n        if do_classifier_free_guidance:\n            negative_prompt = \"\"\n            negative_prompt = (\n                batch_size * [negative_prompt]\n                if isinstance(negative_prompt, str)\n                else negative_prompt\n            )\n\n            if prompt is not None and type(prompt) is not type(negative_prompt):\n                raise TypeError(\n                    f\"`negative_prompt` should be the same type to `prompt`, but got {type(negative_prompt)} !=\"\n                    f\" {type(prompt)}.\"\n                )\n            elif batch_size != len(negative_prompt):\n                raise ValueError(\n                    f\"`negative_prompt`: {negative_prompt} has batch size {len(negative_prompt)}, but `prompt`:\"\n                    f\" {prompt} has batch size {batch_size}. Please make sure that passed `negative_prompt` matches\"\n                    \" the batch size of `prompt`.\"\n                )\n\n            negative_prompt_embeds = self._get_glyph_embeds(\n                negative_prompt, max_sequence_length, device, dtype\n            )\n\n            seq_len = negative_prompt_embeds.size(1)\n            negative_prompt_embeds = negative_prompt_embeds.repeat(1, 1, 1)\n            negative_prompt_embeds = negative_prompt_embeds.reshape(1, seq_len, -1)\n","sourceCodeStart":1009,"sourceCodeEnd":1045,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/multimodal_gen/runtime/pipelines_core/stages/model_specific_stages/glm_image.py#L1009-L1045","documentation":"Diffusers-style input validation in encode_prompt: negative_prompt must have the exact same Python type as prompt (both str, or both list). Passing a list negative_prompt with a str prompt (or vice versa) raises TypeError before any encoding happens.","triggerScenarios":"Calling forward()/encode_prompt with prompt=\"a cat\" (str) and negative_prompt=[\"blurry\"] (list), or prompt=[\"a cat\",\"a dog\"] with negative_prompt=\"blurry\" (str).","commonSituations":"Copy-pasting examples that build negative prompts as lists for batching but use a scalar prompt; dynamically switching between single and batched inference while reusing a negative_prompt variable; UI code that always wraps user text in a list.","solutions":["Make both arguments the same type: either both plain str or both list","For batched runs, pass negative_prompt as a list matching the prompt list length","Add a normalization step in caller code: negative_prompt = [negative_prompt] if isinstance(negative_prompt, str) and isinstance(prompt, list) else negative_prompt"],"exampleFix":"# before\npipe(prompt=[\"a cat\", \"a dog\"], negative_prompt=\"blurry\")\n\n# after\npipe(prompt=[\"a cat\", \"a dog\"], negative_prompt=[\"blurry\", \"blurry\"])","handlingStrategy":"type-guard","validationCode":"if prompt is not None and negative_prompt is not None:\n    assert type(prompt) is type(negative_prompt), (\n        f\"{type(prompt)} vs {type(negative_prompt)}\"\n    )","typeGuard":"def prompt_types_match(prompt, negative_prompt) -> bool:\n    if prompt is None or negative_prompt is None:\n        return True\n    if isinstance(prompt, str):\n        return isinstance(negative_prompt, str)\n    return isinstance(negative_prompt, list)","tryCatchPattern":"except TypeError as e:\n    if \"same type\" in str(e):\n        negative_prompt = [negative_prompt] if isinstance(prompt, list) else str(negative_prompt)\n        retry_call()\n    else:\n        raise","preventionTips":["Normalize negative_prompt to prompt's type in a wrapper before calling","Keep a single convention (always lists) across your codebase","Add unit tests for scalar and list prompt combinations"],"tags":["glm-image","negative-prompt","type-mismatch","input-validation","typeerror"],"backgroundTag":"input-type-mismatch","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}