Skip to content

fix: #477 Add defensive error handling for malformed LLM response choices#667

Merged
param20h merged 1 commit into
param20h:devfrom
suhaniiz:fix-llm-error-handling-477
Jun 23, 2026
Merged

fix: #477 Add defensive error handling for malformed LLM response choices#667
param20h merged 1 commit into
param20h:devfrom
suhaniiz:fix-llm-error-handling-477

Conversation

@suhaniiz

Copy link
Copy Markdown
Contributor

📋 PR Checklist

Thank you for contributing to PDF-Assistant-RAG! 🎉
Please fill out this template before submitting. PRs without it filled in will be closed.


🔗 Related Issue

Closes #477


📝 What does this PR do?

Adds defensive attribute retrieval using getattr when parsing the LLM client's chat completion choices. Previously, the logic assumed that if response.choices was populated, the nested .message and .content attributes were guaranteed to exist, causing an unhandled AttributeError on unexpected schemas or partial API responses. This fix ensures the application safely falls back to returning None without crashing.


🗂️ Type of Change

  • 🐛 Bug fix
  • ✨ New feature
  • 🔧 Refactor / code cleanup
  • 📝 Documentation update
  • 🎨 UI / styling change
  • ⚙️ CI / tooling / config change
  • 🧪 Tests

🧪 How was this tested?

  • Tested the affected API endpoints manually
  • Verified that the code changes cleanly replace only the target fallback block without touching unrelated application logic.

📸 Screenshots (if UI change)

N/A - Backend logic fix only.


⚠️ Anything to flag for reviewers?

No major concerns. The change is isolated strictly inside generate_document_summary and builds upon the existing default return patterns.


✅ Self-Review Checklist

  • My branch is based on dev, not main
  • I have not added any secrets / API keys
  • I have not modified main branch or any HuggingFace deployment config
  • My code follows the existing style (no unnecessary formatting changes)
  • I have updated relevant docs / comments if needed

@suhaniiz suhaniiz requested a review from param20h as a code owner June 22, 2026 12:15
@suhaniiz

Copy link
Copy Markdown
Contributor Author

@param20h , this pr is under gssoc 2026, kindly review it

@param20h param20h merged commit 7a2c1f6 into param20h:dev Jun 23, 2026
8 checks passed
@github-actions github-actions Bot added bug Something isn't working gssoc GirlScript Summer of Code 2026 issue/PR gssoc:approved Approved for GSSoC base points (+50 pts) mentor:param20h Mentor for this PR labels Jun 23, 2026
@param20h param20h added level:intermediate +35 pts type:accessibility +15 pts and removed bug Something isn't working labels Jun 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gssoc:approved Approved for GSSoC base points (+50 pts) gssoc GirlScript Summer of Code 2026 issue/PR level:intermediate +35 pts mentor:param20h Mentor for this PR type:accessibility +15 pts

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Add defensive error handling for malformed or empty LLM response choices

2 participants