{"record":{"id":"21e1311ec7c289ae","repo":"AUTOMATIC1111/stable-diffusion-webui","slug":"prompt-s-r-did-not-find-xs-0-in-prompt-or-negat","errorCode":null,"errorMessage":"Prompt S/R did not find {xs[0]} in prompt or negative prompt.","messagePattern":"Prompt S/R did not find (.+?) in prompt or negative prompt\\.","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"scripts/xyz_grid.py","lineNumber":39,"sourceCode":"import re\r\n\r\nfrom modules.ui_components import ToolButton\r\n\r\nfill_values_symbol = \"\\U0001f4d2\"  # 📒\r\n\r\nAxisInfo = namedtuple('AxisInfo', ['axis', 'values'])\r\n\r\n\r\ndef apply_field(field):\r\n    def fun(p, x, xs):\r\n        setattr(p, field, x)\r\n\r\n    return fun\r\n\r\n\r\ndef apply_prompt(p, x, xs):\r\n    if xs[0] not in p.prompt and xs[0] not in p.negative_prompt:\r\n        raise RuntimeError(f\"Prompt S/R did not find {xs[0]} in prompt or negative prompt.\")\r\n\r\n    p.prompt = p.prompt.replace(xs[0], x)\r\n    p.negative_prompt = p.negative_prompt.replace(xs[0], x)\r\n\r\n\r\ndef apply_order(p, x, xs):\r\n    token_order = []\r\n\r\n    # Initially grab the tokens from the prompt, so they can be replaced in order of earliest seen\r\n    for token in x:\r\n        token_order.append((p.prompt.find(token), token))\r\n\r\n    token_order.sort(key=lambda t: t[0])\r\n\r\n    prompt_parts = []\r\n\r\n    # Split the prompt up, taking out the tokens\r\n    for _, token in token_order:\r","sourceCodeStart":21,"sourceCodeEnd":57,"githubUrl":"https://github.com/AUTOMATIC1111/stable-diffusion-webui/blob/82a973c04367123ae98bd9abdf80d9eda9b910e2/scripts/xyz_grid.py#L21-L57","documentation":"Thrown by the Prompt S/R (search/replace) axis handler in the XYZ Grid script of AUTOMATIC1111's stable-diffusion-webui. Before replacing text, it verifies that the first value of the comma-separated axis list (the search term) actually occurs in either the prompt or the negative prompt. If the search token is absent from both, replacement is impossible, so it aborts immediately with a RuntimeError.","triggerScenarios":"Adding an axis of type 'Prompt S/R' whose first list entry (e.g. \"12345,67890\" -> search term \"12345\") does not appear verbatim in the main prompt or negative prompt of the generation request. Common with batch scripts or API calls (/imgrun or --api with xyz_grid extension) where the prompt template was changed but the axis values were not.","commonSituations":"Typos or case differences between the search token and the prompt text; prompts built dynamically where the token is only inserted for some jobs; copying an axis list from another workflow whose prompt contained the token; leading/trailing whitespace mismatches after CSV parsing.","solutions":["Make sure the first value of the Prompt S/R axis list appears exactly (case-sensitive substring) in the prompt or negative prompt, e.g. prompt contains 'a photo of a dog' and axis values are 'dog,cat'.","Check for case and whitespace mismatches: 'Dog' will not match 'dog', and ' dog' will not match 'dog' after CSV splitting.","If building requests programmatically, assert p.prompt contains xs[0] before launching the grid run.","Use quotes around CSV fields containing commas so the search term is not split incorrectly."],"exampleFix":"# before\nprompt = \"a photo of a cat\"\naxis_values = \"dog,cat\"  # 'dog' not in prompt -> RuntimeError\n\n# after\nprompt = \"a photo of a dog\"\naxis_values = \"dog,cat\"  # 'dog' found; replaced with 'cat' per cell","handlingStrategy":"validation","validationCode":"# before running the grid, verify the S/R search term is present\ndef sr_axis_ok(prompt: str, negative_prompt: str, xs: list[str]) -> bool:\n    return xs[0] in prompt or xs[0] in negative_prompt\n\nassert sr_axis_ok(p.prompt, p.negative_prompt, [\"dog\", \"cat\"]), \\\n    f\"Prompt S/R search term 'dog' missing from prompt and negative prompt\"","typeGuard":"def is_valid_sr_axis(prompt: str, negative_prompt: str, xs: list) -> bool:\n    \"\"\"True when the first Prompt S/R value occurs in prompt or negative_prompt.\"\"\"\n    return isinstance(xs, list) and len(xs) > 0 and isinstance(xs[0], str) and \\\n        (xs[0] in prompt or xs[0] in negative_prompt)","tryCatchPattern":"try:\n    run_xyz_grid(p, axis_list)\nexcept RuntimeError as e:\n    if \"Prompt S/R did not find\" in str(e):\n        log.warning(\"S/R token missing; fixing prompt and retrying\")\n        p.prompt = p.prompt.replace(old_token, xs[0])\n    else:\n        raise","preventionTips":["Treat the first element of a Prompt S/R list as a required substring of the prompt; document this in team templates.","Normalize whitespace and strip CSV fields before passing axis values.","In automated pipelines, assert the search token is present before launching the run."],"tags":["stable-diffusion-webui","xyz-grid","prompt","validation","user-input"],"backgroundTag":null,"analyzedSha":"82a973c04367123ae98bd9abdf80d9eda9b910e2","analyzedAt":"2026-08-14T16:46:43.225Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}