{"record":{"id":"d58f597cc87d30e5","repo":"binary-husky/gpt_academic","slug":"query-type-d58f59","errorCode":null,"errorMessage":"无法提取query_type标签内容","messagePattern":"无法提取query_type标签内容","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"crazy_functions/review_fns/query_analyzer.py","lineNumber":197,"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            # 解析arXiv参数\n            try:\n                arxiv_params = {\n                    \"query\": self._extract_tag(extracted_responses[self.ARXIV_QUERY_INDEX], \"query\"),\n                    \"categories\": [cat.strip() for cat in\n                                   self._extract_tag(extracted_responses[self.ARXIV_CATEGORIES_INDEX],\n                                                     \"categories\").split(\",\")],\n                    \"sort_by\": self._extract_tag(extracted_responses[self.ARXIV_SORT_INDEX], \"sort_by\"),\n                    \"sort_order\": self._extract_tag(extracted_responses[self.ARXIV_SORT_INDEX], \"sort_order\"),","sourceCodeStart":179,"sourceCodeEnd":215,"githubUrl":"https://github.com/binary-husky/gpt_academic/blob/d6bde0fa54373309bd05823a49bda8da019d2c77/crazy_functions/review_fns/query_analyzer.py#L179-L215","documentation":"After collecting responses, QueryAnalyzer extracts the <query_type>...</query_type> tag from the basic-info prompt's response via _extract_tag; an empty match raises Exception('无法提取query_type标签内容'). The debug print right before shows the raw response, so the root cause is the model not following the tag format — truncated, refusals, markdown-fenced output, or a different language.","triggerScenarios":"The LLM answers the BASIC prompt without literal <query_type> tags (writes 'Query type: review' instead), the response is truncated by max-token limits before the tag, the model wraps tags in code fences with escaped angle brackets (&lt;query_type&gt;), or the response is an error/refusal message.","commonSituations":"Weaker/local models ignoring prompt format instructions; max_tokens too small so the tag never appears; temperature/regenerate differences; prompt template drift after model upgrade; HTML-escaped tags when the response passes through markdown rendering.","solutions":["Read the printed Debug line to see what the model actually returned and adapt the prompt ('MUST wrap the answer in <query_type>...</query_type> tags, no markdown fence').","Increase max_token for the basic prompt so the response is not truncated before the tag.","Make _extract_tag tolerant: strip code fences and unescape HTML entities (&lt; &gt;) before regex matching, and fall back to keyword-based classification (the class already has _normalize_query_type keyword fallback).","Use a stronger/instruction-following model for the analyzer step."],"exampleFix":"# before\nm = re.search(f'<{tag}>(.*?)</{tag}>', text, re.DOTALL)\n\n# after (tolerate fenced/escaped tags)\ntext = text.replace('&lt;', '<').replace('&gt;', '>')\ntext = re.sub(r'^```.*?$', '', text, flags=re.MULTILINE)\nm = re.search(f'<{tag}>(.*?)</{tag}>', text, re.DOTALL)","handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    result = analyzer.analyze(query)\nexcept Exception as e:\n    if 'query_type' in str(e):\n        # model ignored the tag format: fall back to keyword heuristics\n        qtype = analyzer._normalize_query_type('', query)\n        result = default_analyzed_query(query, qtype)\n    else:\n        raise","preventionTips":["State the tag format in the prompt explicitly and forbid markdown fences around it.","Give the basic-info prompt enough max_token budget to finish.","Keep a keyword-based classifier as fallback for models with weak instruction following."],"tags":["llm","prompt-format","parsing","query-analyzer","truncation"],"backgroundTag":null,"analyzedSha":"d6bde0fa54373309bd05823a49bda8da019d2c77","analyzedAt":"2026-08-14T22:48:35.038Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}