{"record":{"id":"4e0e6b3afb679375","repo":"HKUDS/DeepTutor","slug":"quiz-generation-failed-exc","errorCode":null,"errorMessage":"quiz generation failed: {exc}","messagePattern":"quiz generation failed: (.+?)","errorType":"exception","errorClass":"GenerationFailure","httpStatus":null,"severity":"error","filePath":"deeptutor/book/blocks/quiz.py","lineNumber":68,"sourceCode":"            pipeline = QuestionPipeline(language=ctx.language, kb_name=effective_kb)\n            result = await pipeline.run(\n                context=UnifiedContext(\n                    session_id=f\"book-{ctx.book_id}\",\n                    user_message=topic,\n                    active_capability=\"deep_question\",\n                    knowledge_bases=[effective_kb] if effective_kb else [],\n                    language=ctx.language,\n                ),\n                user_message=topic,\n                num_questions=max(1, int(num_questions or 1)),\n                difficulty=difficulty,\n                question_types=question_types,\n                stream=get_book_bus(ctx.book_id),\n            )\n            summary = dict(result.get(\"summary\") or {})\n        except Exception as exc:\n            logger.warning(f\"QuizGenerator failed: {exc}\", exc_info=True)\n            raise GenerationFailure(f\"quiz generation failed: {exc}\") from exc\n\n        questions = self._extract_questions(summary)\n        if not questions:\n            raise GenerationFailure(\"no questions generated\")\n\n        return (\n            {\"questions\": questions, \"topic\": topic},\n            [],\n            {\n                \"completed\": summary.get(\"completed\", 0),\n                \"failed\": summary.get(\"failed\", 0),\n                \"kb\": ctx.primary_kb,\n            },\n        )\n\n    @staticmethod\n    def _extract_questions(summary: dict[str, Any]) -> list[dict[str, Any]]:\n        results = summary.get(\"results\") or []","sourceCodeStart":50,"sourceCodeEnd":86,"githubUrl":"https://github.com/HKUDS/DeepTutor/blob/3e82f130422a813cdd73c10b21a44e9325f5821a/deeptutor/book/blocks/quiz.py#L50-L86","documentation":"The quiz block wraps the QuizGenerator call in try/except; any exception it throws (LLM/provider errors, internal quiz pipeline failures) is re-raised as GenerationFailure('quiz generation failed: ...') with the original exception chained and logged as a warning with traceback.","triggerScenarios":"Calling quiz _generate when QuizGenerator raises — LLM auth/network/rate-limit errors, failures inside its multi-question generation loop (it receives question_types and the book stream bus), or context problems passed via ctx (e.g. missing KB).","commonSituations":"Expired API key; rate limits during multi-question generation; RagContext/topic empty causing internal assertion; stream bus errors; QuizGenerator package API changed between versions.","solutions":["Check the logged warning traceback for the root exc","Resolve provider issues (key, quota, network) first","Retry the quiz block — multi-step LLM loops fail transiently","Verify ctx (topic, rag context, book_id bus) is populated before invoking"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"assert llm_client_ready(), 'LLM provider unavailable before quiz generation'\nassert topic and topic.strip(), 'quiz requires a non-empty topic'","typeGuard":null,"tryCatchPattern":"try:\n    return await quiz_block.generate(ctx)\nexcept GenerationFailure as exc:\n    logger.warning('quiz failed: %s (cause: %s)', exc, exc.__cause__)\n    return fallback_quiz(ctx)  # cached/static quiz or skip","preventionTips":["Verify API key/quota before multi-question generation runs","Ensure ctx topic and RAG context are populated","Read the chained cause in logs; the wrapper message hides the real error"],"tags":["quiz","llm-pipeline","wrapper-exception","generation"],"backgroundTag":"llm-generation-pipeline-failure","analyzedSha":"3e82f130422a813cdd73c10b21a44e9325f5821a","analyzedAt":"2026-08-27T06:57:25.364Z","schemaVersion":2},"datasetVersion":"2026-08-27T08:17:20.692Z"}