{"record":{"id":"fe3863321fbb48d0","repo":"langchain-ai/langchain","slug":"invalid-prompt-input","errorCode":"INVALID_PROMPT_INPUT","errorMessage":"Cannot have an input variable named 'stop', as it is used internally, please rename.","messagePattern":"Cannot have an input variable named 'stop', as it is used internally, please rename\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"libs/core/langchain_core/prompts/base.py","lineNumber":88,"sourceCode":"    Partial variables populate the template so that you don't need to pass them in every\n    time you call the prompt.\n    \"\"\"\n\n    metadata: builtins.dict[str, Any] | None = None\n    \"\"\"Metadata to be used for tracing.\"\"\"\n\n    tags: list[str] | None = None\n    \"\"\"Tags to be used for tracing.\"\"\"\n\n    @model_validator(mode=\"after\")\n    def validate_variable_names(self) -> Self:\n        \"\"\"Validate variable names do not include restricted names.\"\"\"\n        if \"stop\" in self.input_variables:\n            msg = (\n                \"Cannot have an input variable named 'stop', as it is used internally,\"\n                \" please rename.\"\n            )\n            raise ValueError(\n                create_message(message=msg, error_code=ErrorCode.INVALID_PROMPT_INPUT)\n            )\n        if \"stop\" in self.partial_variables:\n            msg = (\n                \"Cannot have an partial variable named 'stop', as it is used \"\n                \"internally, please rename.\"\n            )\n            raise ValueError(\n                create_message(message=msg, error_code=ErrorCode.INVALID_PROMPT_INPUT)\n            )\n\n        overall = set(self.input_variables).intersection(self.partial_variables)\n        if overall:\n            msg = f\"Found overlapping input and partial variables: {overall}\"\n            raise ValueError(\n                create_message(message=msg, error_code=ErrorCode.INVALID_PROMPT_INPUT)\n            )\n        return self","sourceCodeStart":70,"sourceCodeEnd":106,"githubUrl":"https://github.com/langchain-ai/langchain/blob/e32fa9a52eab3b61ad7a45399bfde59b3e580fc4/libs/core/langchain_core/prompts/base.py#L70-L106","documentation":"BasePromptTemplate's model validator (mode='after') rejects any prompt whose input_variables contains the name 'stop'. 'stop' is reserved because prompt templates inject stop sequences internally when invoking models, so a user variable with that name would collide. Thrown as ValueError with error code INVALID_PROMPT_INPUT at validation time (object construction), not at format time.","triggerScenarios":"Constructing any prompt template (PromptTemplate, ChatPromptTemplate, etc.) with input_variables=['stop'], a template string containing {stop}, or from_template('... {stop} ...'). Fires immediately on instantiation because it is a Pydantic model_validator.","commonSituations":"Templates about traffic controls, stop-words filters, music (stop time), or transcription prompts that legitimately use the word 'stop' as a placeholder. Also migrations from older code that passed stop via template variables instead of the stop parameter on generate/invoke.","solutions":["Rename the variable in the template and in all supplied values, e.g. {stop} -> {halt} or {stop_word}","If you meant to pass stop sequences to the model, supply them via the stop parameter of invoke/generate or as a runtime kwarg, not as a template variable"],"exampleFix":"# before\nPromptTemplate.from_template(\"List {stop} words\")  # ValueError\n\n# after\nPromptTemplate.from_template(\"List {stop_word} words\")\n# and pass stop sequences at call time: chain.invoke({\"stop_word\": ...}, config={\"stop\": [...]})","handlingStrategy":"validation","validationCode":"RESERVED = {\"stop\"}\n\ndef check_template(src: str) -> None:\n    from langchain_core.prompts.string import get_template_variables\n    bad = RESERVED & set(get_template_variables(src, \"f-string\"))\n    if bad:\n        msg = f\"reserved variable names in template: {bad}\"\n        raise ValueError(msg)","typeGuard":null,"tryCatchPattern":"try:\n    prompt = PromptTemplate.from_template(src)\nexcept ValueError as e:\n    if \"stop\" in str(e):\n        src = src.replace(\"{stop}\", \"{halt}\")\n        prompt = PromptTemplate.from_template(src)\n    else:\n        raise","preventionTips":["Never use 'stop' as a placeholder name; reserve it mentally for stop sequences","Lint template strings for {stop} in CI when templates come from external files"],"tags":["prompts","validation","reserved-name","core"],"backgroundTag":null,"analyzedSha":"e32fa9a52eab3b61ad7a45399bfde59b3e580fc4","analyzedAt":"2026-08-14T18:42:09.092Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}