HKUDS/DeepTutor · error · ValueError

CodeGeneratorAgent retry prompts are not configured.

Error message

CodeGeneratorAgent retry prompts are not configured.

What it means

Raised by the pypdf fallback branch of _extract_pdf when reader.is_encrypted is true. It mirrors the pymupdf branch: pypdf cannot extract text from an encrypted PDF without a password, so a CorruptDocumentError with the filename is raised.

Source

Thrown at deeptutor/agents/math_animator/agents/code_generator_agent.py:106

        ):
            _chunks.append(_c)
        response = "".join(_chunks)
        return GeneratedCode.model_validate(extract_json_object(response))

    async def repair(
        self,
        *,
        user_input: str,
        output_mode: str,
        current_code: str,
        error_message: str,
        attempt: int,
        duration_target_seconds: float | None = None,
    ) -> GeneratedCode:
        system_prompt = self.get_prompt("retry_system")
        user_template = self.get_prompt("retry_user_template")
        if not system_prompt or not user_template:
            raise ValueError("CodeGeneratorAgent retry prompts are not configured.")

        user_prompt = user_template.format(
            user_input=user_input.strip(),
            output_mode=output_mode,
            attempt=attempt,
            duration_requirement=(
                f"目标时长约 {duration_target_seconds:.1f} 秒,修复后仍需保持接近该时长。"
                if duration_target_seconds is not None
                else "无明确目标时长。"
            ),
            error_message=build_repair_error_message(error_message),
            current_code=current_code,
        )
        _chunks: list[str] = []
        async for _c in self.stream_llm(
            user_prompt=user_prompt,
            system_prompt=system_prompt,
            response_format={"type": "json_object"},

View on GitHub (pinned to 3e82f13042)

Solutions

  1. Decrypt with pikepdf or qpdf before extraction
  2. Provide the password, decrypt via pypdf's reader.decrypt(pw), re-serialize, then extract
  3. Skip encrypted PDFs during batch ingestion with a logged warning

Example fix

// before
reader = PdfReader(io.BytesIO(data))
if getattr(reader, "is_encrypted", False):
    raise CorruptDocumentError(...)

// after
reader = PdfReader(io.BytesIO(data))
if reader.is_encrypted:
    reader.decrypt(pw)  # or pre-decrypt with pikepdf
pages = [p.extract_text() for p in reader.pages]
Defensive patterns

Strategy: try-catch

Validate before calling

from pypdf import PdfReader
import io
try:
    r = PdfReader(io.BytesIO(data))
    encrypted = bool(getattr(r, "is_encrypted", False))
except Exception:
    encrypted = False
if encrypted:
    request_password_or_skip()

Try / catch

except CorruptDocumentError as e:
    if "encrypted" in str(e):
        skip_file_with_reason(fn, "encrypted PDF")

Prevention

When it happens

Trigger: Environment has pypdf but not pymupdf, and the PDF passed to extract_text_from_bytes has encryption enabled with a non-empty user password.

Common situations: Same encrypted-document ingestion scenarios as the fitz branch, but in slim environments where only pypdf is installed.

Related errors


AI-assisted analysis of HKUDS/DeepTutor@3e82f13042 (2026-08-27). Data as JSON: /api/errors/f72f9f4ddee6d5bf. Report an issue: GitHub.