{"record":{"id":"8abdf08356d5e3c0","repo":"langchain-ai/langchain","slug":"unsupported-operand-type-for-type-other","errorCode":null,"errorMessage":"Unsupported operand type for +: {type(other)}","messagePattern":"Unsupported operand type for \\+: (.+?)","errorType":"exception","errorClass":"NotImplementedError","httpStatus":null,"severity":"error","filePath":"libs/core/langchain_core/prompts/chat.py","lineNumber":1049,"sourceCode":"            )\n        if isinstance(\n            other, (BaseMessagePromptTemplate, BaseMessage, BaseChatPromptTemplate)\n        ):\n            return ChatPromptTemplate(messages=[*self.messages, other]).partial(\n                **partials\n            )\n        if isinstance(other, (list, tuple)):\n            other_ = ChatPromptTemplate.from_messages(other)\n            return ChatPromptTemplate(messages=self.messages + other_.messages).partial(\n                **partials\n            )\n        if isinstance(other, str):\n            prompt = HumanMessagePromptTemplate.from_template(other)\n            return ChatPromptTemplate(messages=[*self.messages, prompt]).partial(\n                **partials\n            )\n        msg = f\"Unsupported operand type for +: {type(other)}\"\n        raise NotImplementedError(msg)\n\n    @model_validator(mode=\"before\")\n    @classmethod\n    def validate_input_variables(cls, values: dict[str, Any]) -> Any:\n        \"\"\"Validate input variables.\n\n        If `input_variables` is not set, it will be set to the union of all input\n        variables in the messages.\n\n        Args:\n            values: values to validate.\n\n        Returns:\n            Validated values.\n\n        Raises:\n            ValueError: If input variables do not match.\n        \"\"\"","sourceCodeStart":1031,"sourceCodeEnd":1067,"githubUrl":"https://github.com/langchain-ai/langchain/blob/e32fa9a52eab3b61ad7a45399bfde59b3e580fc4/libs/core/langchain_core/prompts/chat.py#L1031-L1067","documentation":"ChatPromptTemplate.__add__ supports concatenating a string, list, or tuple of messages/templates on the right side; anything else raises NotImplementedError('Unsupported operand type for +: {type}'). This operator is a convenience for extending a prompt, not general addition — ints, dicts, other prompt objects (non-chat), or Runnables are rejected.","triggerScenarios":"prompt + 5, prompt + {'role': ...}, prompt + some_string_generator, or prompt + another_prompt where the right side is not one of str/list/tuple. Note a bare dict is NOT accepted even though from_messages accepts dict elements inside a list.","commonSituations":"Developers assume prompt1 + prompt2 composes two ChatPromptTemplates; or splat a **kwargs dict onto +; or add a single message object instead of wrapping it in a list.","solutions":["Wrap the right side in a list: prompt + [message_or_template]","For plain text, add the string directly: prompt + \"Summarize the above\" (becomes a human message)","To compose two ChatPromptTemplates, use ChatPromptTemplate.from_messages([*p1.messages, *p2.messages])"],"exampleFix":"# before\nmerged = base_prompt + followup_prompt  # NotImplementedError (not str/list/tuple path)\n\n# after\nmerged = ChatPromptTemplate.from_messages(\n    [*base_prompt.messages, *followup_prompt.messages]\n)","handlingStrategy":"type-guard","validationCode":"def add_to_prompt(prompt, other):\n    if isinstance(other, (str, list, tuple)):\n        return prompt + other\n    msg = f\"cannot add {type(other)} to ChatPromptTemplate; wrap in a list\"\n    raise TypeError(msg)","typeGuard":"def is_addable_to_chat_prompt(other) -> bool:\n    return isinstance(other, (str, list, tuple))","tryCatchPattern":"try:\n    merged = prompt + other\nexcept NotImplementedError:\n    merged = prompt + [other]  # wrap and retry","preventionTips":["Always wrap single messages or templates in a list when using +","Compose two ChatPromptTemplates via from_messages([*a.messages, *b.messages])"],"tags":["prompts","chat","operator-overload","core"],"backgroundTag":null,"analyzedSha":"e32fa9a52eab3b61ad7a45399bfde59b3e580fc4","analyzedAt":"2026-08-14T18:42:09.092Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}