{"record":{"id":"1f0e625d02841f3c","repo":"binary-husky/gpt_academic","slug":"query-type","errorCode":null,"errorMessage":"无法提取query_type标签内容","messagePattern":"无法提取query_type标签内容","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"crazy_functions/paper_fns/auto_git/query_analyzer.py","lineNumber":233,"sourceCode":"                if (i * 2 + 1) < len(responses):\n                    response = responses[i * 2 + 1]\n                    if response is None:\n                        raise Exception(f\"Response {i} is None\")\n                    if not isinstance(response, str):\n                        try:\n                            response = str(response)\n                        except:\n                            raise Exception(f\"Cannot convert response {i} to string\")\n                    extracted_responses.append(response)\n                else:\n                    raise Exception(f\"未收到第 {i + 1} 个响应\")\n\n            # 解析基本信息\n            query_type = self._extract_tag(extracted_responses[self.BASIC_QUERY_INDEX], \"query_type\")\n            if not query_type:\n                print(\n                    f\"Debug - Failed to extract query_type. Response was: {extracted_responses[self.BASIC_QUERY_INDEX]}\")\n                raise Exception(\"无法提取query_type标签内容\")\n            query_type = query_type.lower()\n\n            main_topic = self._extract_tag(extracted_responses[self.BASIC_QUERY_INDEX], \"main_topic\")\n            if not main_topic:\n                print(f\"Debug - Failed to extract main_topic. Using query as fallback.\")\n                main_topic = query\n\n            query_type = self._normalize_query_type(query_type, query)\n\n            # 提取子主题\n            sub_topics = []\n            sub_topics_text = self._extract_tag(extracted_responses[self.BASIC_QUERY_INDEX], \"sub_topics\")\n            if sub_topics_text:\n                sub_topics = [topic.strip() for topic in sub_topics_text.split(\",\")]\n\n            # 提取语言\n            language = self._extract_tag(extracted_responses[self.BASIC_QUERY_INDEX], \"language\")\n","sourceCodeStart":215,"sourceCodeEnd":251,"githubUrl":"https://github.com/binary-husky/gpt_academic/blob/d6bde0fa54373309bd05823a49bda8da019d2c77/crazy_functions/paper_fns/auto_git/query_analyzer.py#L215-L251","documentation":"The first LLM response was received but _extract_tag() could not find a <query_type>...</query_type> tag in it. The analyzer asks the model to emit structured XML-ish tags; if the model omits the tag, wraps it in markdown fences, or outputs a preamble before the tag, extraction fails and the exception is raised. This is a prompt-format compliance failure, not a network error.","triggerScenarios":"Model returns malformed output (no <query_type> tag), wraps tags in code fences, answers in a different language/format, or truncates output before the tag; regex in _extract_tag is case-sensitive or whitespace-sensitive and the model emits <Query_Type>.","commonSituations":"Switching to a smaller/less instruction-following model; temperature too high producing chatty preambles; max_tokens set too low so output truncates before the tag; prompt template edited without testing tag format.","solutions":["The debug print just above shows the raw response — read it to see exactly why the tag is missing","Tighten the prompt to demand output like '<query_type>repo</query_type>...' with no extra text","Make _extract_tag tolerant: strip markdown fences, use re.IGNORECASE, allow surrounding whitespace","As a fallback, skip the tag and let _normalize_query_type infer the type from keyword matching (the code path already exists below)"],"exampleFix":"// before\nquery_type = self._extract_tag(extracted_responses[self.BASIC_QUERY_INDEX], \"query_type\")\nif not query_type:\n    raise Exception(\"无法提取query_type标签内容\")\n\n// after\nquery_type = self._extract_tag(extracted_responses[self.BASIC_QUERY_INDEX], \"query_type\")\nif not query_type:\n    query_type = self._normalize_query_type(\"\", query)  # keyword-based inference fallback\nif not query_type:\n    raise Exception(\"无法提取query_type标签内容\")","handlingStrategy":"fallback","validationCode":"import re\nTAG = re.compile(r'<query_type>\\s*(.*?)\\s*</query_type>', re.IGNORECASE | re.DOTALL)\ndef has_query_type_tag(response: str) -> bool:\n    return bool(TAG.search(response))","typeGuard":null,"tryCatchPattern":"try:\n    criteria = analyzer.analyze(query)\nexcept Exception as e:\n    if \"query_type\" in str(e):\n        criteria = analyzer.analyze_with_defaults(query)  # keyword-based fallback path","preventionTips":["Prompt for machine-parseable tag output and include a worked example in the system prompt","Strip markdown fences and leading prose before tag extraction","Always wire _normalize_query_type's keyword inference as the fallback instead of hard-failing"],"tags":["llm","prompt-format","parsing","query-analyzer"],"backgroundTag":null,"analyzedSha":"d6bde0fa54373309bd05823a49bda8da019d2c77","analyzedAt":"2026-08-14T22:48:35.038Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}