{"record":{"id":"07cdf847c47024f7","repo":"infiniflow/ragflow","slug":"miss-parameter-key","errorCode":null,"errorMessage":"Miss parameter: {key}","messagePattern":"Miss parameter: (.+?)","errorType":"exception","errorClass":"KeyError","httpStatus":null,"severity":"error","filePath":"api/db/services/dialog_service.py","lineNumber":700,"sourceCode":"            yield ans\n            return\n        else:\n            logging.debug(\"SQL failed or returned no results, falling back to vector search\")\n\n    param_keys = [p[\"key\"] for p in prompt_config.get(\"parameters\", [])]\n    if dialog.kb_ids and \"knowledge\" not in param_keys and \"{knowledge}\" in prompt_config.get(\"system\", \"\"):\n        logging.warning(\"prompt_config['parameters'] is missing 'knowledge' entry despite kb_ids being set; auto-fixing.\")\n        prompt_config.setdefault(\"parameters\", []).append({\"key\": \"knowledge\", \"optional\": False})\n        param_keys.append(\"knowledge\")\n    logging.debug(f\"scoped_doc_ids={scoped_doc_ids}, param_keys={param_keys}, embd_mdl={embd_mdl}\")\n\n    sys_date = datetime.now(timezone.utc).strftime(\"%Y-%m-%d %H:%M:%S\")\n    kwargs[\"date\"] = sys_date\n    for p in prompt_config.get(\"parameters\", []):\n        if p[\"key\"] == \"knowledge\":\n            continue\n        if p[\"key\"] not in kwargs and not p[\"optional\"]:\n            raise KeyError(\"Miss parameter: \" + p[\"key\"])\n        if p[\"key\"] not in kwargs:\n            prompt_config[\"system\"] = prompt_config[\"system\"].replace(\"{%s}\" % p[\"key\"], \" \")\n\n    if len(questions) > 1 and prompt_config.get(\"refine_multiturn\"):\n        questions = [await full_question(dialog.tenant_id, dialog.llm_id, messages)]\n    else:\n        questions = questions[-1:]\n\n    if prompt_config.get(\"cross_languages\"):\n        questions = [await cross_languages(dialog.tenant_id, dialog.llm_id, questions[0], prompt_config[\"cross_languages\"])]\n\n    if prompt_config.get(\"keyword\", False):\n        questions[-1] = questions[-1] + \",\" + await keyword_extraction(chat_mdl, questions[-1])\n    refine_question_ts = timer()\n\n    thought = \"\"\n    kbinfos = {\"total\": 0, \"chunks\": [], \"doc_aggs\": []}\n    knowledges = []","sourceCodeStart":682,"sourceCodeEnd":718,"githubUrl":"https://github.com/infiniflow/ragflow/blob/554fb1133ac3861732235ad9c377eb5e0a770665/api/db/services/dialog_service.py#L682-L718","documentation":"KeyError raised during chat prompt preparation when a prompt_config parameter entry is non-optional and its key is absent from kwargs. Only 'knowledge' is special-cased (auto-appended when kb_ids set); every other declared non-optional parameter must be supplied by the caller.","triggerScenarios":"Calling the chat flow with a dialog whose prompt template declares e.g. {'key': 'user_name', 'optional': false} in prompt_config['parameters'] but the request supplies no user_name variable.","commonSituations":"Editing a chat assistant's system prompt and adding a new {placeholder} marked required without updating the calling code/UI to send it; importing dialog configurations that declare parameters the caller never populates.","solutions":["Pass the missing variable in the request kwargs matching the parameter key.","Mark the parameter as {'optional': true} in the dialog's prompt configuration if it is genuinely optional.","Remove the unused {placeholder} from the system prompt and the parameters list."],"exampleFix":"# before: prompt declares {user_name} required, request omits it\n# after\nresp = ask(chat_id, msg, {'user_name': 'Alice'})\n# or in dialog config: {'key': 'user_name', 'optional': True}","handlingStrategy":"validation","validationCode":"params = dialog['prompt_config'].get('parameters', [])\nmissing = [p['key'] for p in params if p['key'] != 'knowledge' and not p.get('optional') and p['key'] not in kwargs]\nif missing:\n    raise ValueError(f'missing required prompt variables: {missing}')","typeGuard":null,"tryCatchPattern":"try:\n    chat(dialog, messages, **vars)\nexcept KeyError as e:\n    var = str(e).strip(\"'\").replace('Miss parameter: ', '')\n    vars[var] = ask_user_for(var)  # or mark optional in dialog config\n    chat(dialog, messages, **vars)","preventionTips":["Keep prompt parameters and caller-supplied variables in one shared schema definition.","Default new prompt variables to optional:true unless truly required."],"tags":["validation","prompt-template","dialog","chat"],"backgroundTag":null,"analyzedSha":"554fb1133ac3861732235ad9c377eb5e0a770665","analyzedAt":"2026-08-15T09:20:16.380Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}