binary-husky/gpt_academic · error · Exception
Failed to analyze query: {str(e)}
Error message
Failed to analyze query: {str(e)} What it means
The outermost wrapper of QueryAnalyzer.analyze: every exception raised inside the method (errors 90-93, parameter parsing, any unexpected error) is caught and re-raised as Exception('Failed to analyze query: {str(e)}'). It preserves the original message but destroys the original exception type and traceback, so diagnosis requires reading the embedded text.
Source
Thrown at crazy_functions/review_fns/query_analyzer.py:398
return SearchCriteria(
query_type=query_type,
main_topic=main_topic,
sub_topics=sub_topics,
start_year=start_year,
end_year=end_year,
arxiv_params=arxiv_params,
semantic_params=semantic_params,
pubmed_params=pubmed_params,
crossref_params=crossref_params,
paper_id=paper_id,
paper_title=paper_title,
paper_source=paper_source,
original_query=query,
adsabs_params=adsabs_params
)
except Exception as e:
raise Exception(f"Failed to analyze query: {str(e)}")
def _normalize_query_type(self, query_type: str, query: str) -> str:
"""规范化查询类型"""
if query_type in ["review", "recommend", "qa", "paper"]:
return query_type
query_lower = query.lower()
for type_name, keywords in self.valid_types.items():
for keyword in keywords:
if keyword in query_lower:
return type_name
query_type_lower = query_type.lower()
for type_name, keywords in self.valid_types.items():
for keyword in keywords:
if keyword in query_type_lower:
return type_name
View on GitHub (pinned to d6bde0fa54)
Solutions
- Read the suffix after 'Failed to analyze query:' — it names the real cause; map it to errors 90-93 if it matches.
- Fix the underlying issue (API key/model config, prompt format, retry on transient failure).
- In your own code, catch this exception and degrade gracefully (skip analysis, use default search parameters) rather than crashing the request pipeline.
- If you control the code, re-raise with `raise Exception(...) from e` or use logging.exception to keep the traceback.
Example fix
# before
except Exception as e:
raise Exception(f'Failed to analyze query: {str(e)}')
# after
except Exception as e:
logger.exception('Query analysis failed')
raise Exception(f'Failed to analyze query: {str(e)}') from e Defensive patterns
Strategy: fallback
Try / catch
try:
analyzed = analyzer.analyze(query)
except Exception as e: # 'Failed to analyze query: ...'
logger.warning('analysis failed (%s); using default search params', e)
analyzed = AnalyzedQuery(query_type='paper', original_query=query) # safe defaults Prevention
- Never let analyzer failures kill the user request — default parameters keep search working.
- Log the full embedded message; it identifies which sub-step (90-93) broke.
- Retry once before falling back: most sub-causes are transient API errors.
When it happens
Trigger: Any failure during multi-prompt LLM fan-out or downstream parsing: None responses, missing response slots, unparseable <query_type> tag, invalid arXiv/Semantic Scholar parameter blocks, or attribute errors while assembling the AnalyzedQuery result object.
Common situations: End users see this single message for every analyzer failure; typical underlying causes are LLM API misconfiguration (key/model), non-conforming model output, or transient API errors — all surfaced through this one wrapper.
Related errors
- Cannot convert response {i} to string
- 未收到第 {i + 1} 个响应
- 无法提取query_type标签内容
- 分析查询失败: {str(e)}
- Response {i} is None
AI-assisted analysis of binary-husky/gpt_academic@d6bde0fa54 (2026-08-14).
Data as JSON: /api/errors/b7c94a2912176aa5.
Report an issue: GitHub.