feat(agent): 手持ち PDF 経歴書の構造化抽出エンドポイント(ADR-0024 / #527)#538
Conversation
テキスト埋め込み PDF を pypdf で抽出し、Claude Haiku で Resume 互換 payload に 構造化する同期エンドポイント POST /api/agent/resume-import/pdf を追加。DB 非更新で フォーム注入(#524)の前段まで(ADR-0010 の不変条件を継承)。 - 依存: pypdf==6.14.2(純 Python・native 依存なし)を追加、uv lock 再生成 - services/agent/resume_import/: - text_extract.py: pypdf 抽出 + スキャン判定 + 正規化(決定論・TDD / mutmut 対象追加) - output_schema.py: 見出し3 + フラット職歴の構造化出力スキーマ(v1 スコープ) - import_service.py: LLM 1 コール → パース(リトライ 1 回)→ payload - prompts/agent_resume_import.md: 抽出プロンプト(転記重視・捏造禁止) - schemas/agent.py: ResumeImportResponse(フォーム注入用の緩い payload) - routers/agent.py: エンドポイント(multipart / magic bytes・サイズ上限検証 / 日次レート制限 / 明示的エラー契約 = 非対応PDF 422・LLM 502・パース 502) - messages.json: import_invalid_pdf / import_scanned_pdf / import_too_large - テスト: text_extract 単体 11 件(TDD)+ endpoint 統合 7 件 - generated.ts 再生成 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
Warning Review limit reached
Next review available in: 4 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughAdds an authenticated PDF resume import endpoint that validates and extracts embedded text, uses Claude Haiku to produce a structured resume payload, returns explicit validation and upstream errors, and exposes generated frontend API types with backend and integration tests. ChangesResume import flow
Estimated code review effort: 3 (Moderate) | ~25 minutes Possibly related issues
Suggested labels: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
backend/app/schemas/agent.py (1)
171-199: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winResume-import output shape is defined twice (public schema vs. internal validation model) with no single source of truth.
ResumeImportExperience/ResumeImportResponseinschemas/agent.pyand_ImportExperience/_ImportOutputinimport_service.pydescribe the identical field set, but only the latter carries themax_lengthconstraints (MAX_COMPANY_LENGTH,MAX_DATE_LENGTH, etc.). This means the public OpenAPI schema/generated FE types don't reflect the real length limits, and the two definitions can silently drift on future changes.
backend/app/schemas/agent.py#L171-L199: keep this as the single public contract; haveimport_service.pyimport and reuse these classes (adding themax_lengthField(...)constraints here) instead of maintaining a second private copy.backend/app/services/agent/resume_import/import_service.py#L55-L73: drop_ImportExperience/_ImportOutputand validate directly againstResumeImportExperience/ResumeImportResponse(imported fromschemas.agent) once the length constraints are moved there.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@backend/app/schemas/agent.py` around lines 171 - 199, The resume-import output models are duplicated and their length constraints are only present in the internal validation models. In backend/app/schemas/agent.py lines 171-199, add the existing max-length constraints to ResumeImportExperience and ResumeImportResponse so they define the complete public contract; in backend/app/services/agent/resume_import/import_service.py lines 55-73, remove _ImportExperience and _ImportOutput, import the public models, and validate directly with ResumeImportExperience/ResumeImportResponse.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@backend/app/services/agent/resume_import/text_extract.py`:
- Around line 73-79: Update the PDF parsing exception handler around PdfReader
and page.extract_text to catch the broader PyPdfError type, while retaining a
narrow fallback for malformed-input parser errors such as KeyError and
RecursionError. Preserve the existing type-only warning and PdfExtractionError
wrapping behavior.
---
Nitpick comments:
In `@backend/app/schemas/agent.py`:
- Around line 171-199: The resume-import output models are duplicated and their
length constraints are only present in the internal validation models. In
backend/app/schemas/agent.py lines 171-199, add the existing max-length
constraints to ResumeImportExperience and ResumeImportResponse so they define
the complete public contract; in
backend/app/services/agent/resume_import/import_service.py lines 55-73, remove
_ImportExperience and _ImportOutput, import the public models, and validate
directly with ResumeImportExperience/ResumeImportResponse.
🪄 Autofix (Beta)
❌ Autofix failed (check again to retry)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 9a0a9d0f-ad86-4652-86cc-3a26a59171c0
⛔ Files ignored due to path filters (1)
backend/uv.lockis excluded by!**/*.lock
📒 Files selected for processing (12)
backend/app/messages.jsonbackend/app/prompts/agent_resume_import.mdbackend/app/routers/agent.pybackend/app/schemas/agent.pybackend/app/services/agent/resume_import/__init__.pybackend/app/services/agent/resume_import/import_service.pybackend/app/services/agent/resume_import/output_schema.pybackend/app/services/agent/resume_import/text_extract.pybackend/pyproject.tomlbackend/tests/test_resume_import_api.pybackend/tests/test_resume_import_text_extract.pyweb/src/api/generated.ts
CodeRabbit 指摘(Major)。pypdf は破損 PDF に対し PdfReadError だけでなく、必須キー 欠落(KeyError: /Root・/Pages)や深いネスト(RecursionError)を組み込み例外のまま 送出することがある。従来の except は PdfReadError/ValueError/OSError のみで、これらが 500 として漏れ得た。PyPdfError(基底)+ KeyError + RecursionError も捕捉して 422 (PdfExtractionError)へ倒す。 組み込み例外の wrapping を検証する parametrized テストを追加(PdfReader をモックして KeyError / RecursionError 送出 → PdfExtractionError を確認)。 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
Note Autofix is a beta feature. Expect some limitations and changes as we gather feedback and continue to improve it. Autofix skipped. No unresolved CodeRabbit review comments with fix instructions found. |
概要
ADR-0024 に従い、手持ち PDF 経歴書を構造化抽出する同期エンドポイント
POST /api/agent/resume-import/pdfを追加する(#527 / 3 PR 構成の 2 本目)。テキスト埋め込み PDF を pypdf で抽出 → Claude Haiku で Resume 互換 payload に構造化 → DB 非更新で返す。フォーム注入(#528/#524)の前段まで。変更内容
pypdf==6.14.2(純 Python・MIT・native 依存なし。flake.nix 変更不要)を追加、uv lock再生成services/agent/resume_import/(新規):text_extract.py: pypdf 抽出 + スキャン PDF 判定 + 正規化(決定論・TDD。mutmutonly_mutateに追加)output_schema.py: v1 スコープ(full_name / career_summary / self_pr + フラット experiences)の構造化出力スキーマimport_service.py: LLM 1 コール → パース(リトライ 1 回)→ payload(chat/draft と同一の失敗契約)prompts/agent_resume_import.md: 抽出プロンプト(転記重視・捏造禁止・読み取れないフィールドは空)schemas/agent.py:ResumeImportResponse(フォーム注入用の緩い payload。保存契約とは分離)routers/agent.py: エンドポイント(multipart / magic bytes・10MB 上限検証 / 日次レート制限 [Agent 整理 2/4] ユーザ単位レート制限の導入(課金撤去の前提) #521 / DB 非更新)AGENT_LLM_ERROR/ パース失敗=502AGENT_PARSE_ERRORmessages.json:import_invalid_pdf/import_scanned_pdf/import_too_largev1 スコープ(ADR-0024)
抽出は 見出し 3 フィールド + フラット職歴(company / business_description / start_date / end_date / description)。深いネスト(clients/projects/periods/technology_stacks)は v1 では抽出せず、ユーザーがフォームで追記する。
テスト
text_extract単体 11 件(TDD: 正規化・十分性判定・PDF 判定・抽出・スキャン検出・破損)make cigreen(backend lint+typecheck+test / web 323 / build-web)、make codegen-types再生成済み🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
Bug Fixes
Tests