Skip to content

Fixing gen_answer failover leaving raw_answer blank#1077

Merged
jamesbraza merged 4 commits intomainfrom
removing-empty-docs-error
Aug 26, 2025
Merged

Fixing gen_answer failover leaving raw_answer blank#1077
jamesbraza merged 4 commits intomainfrom
removing-empty-docs-error

Conversation

@jamesbraza
Copy link
Copy Markdown
Collaborator

#1073 was suboptimal in that if the EmptyDocsError route was taken, the PQASession's raw_answer/answer_reasoning would be left unpopulated without patching in-place. This PR:

  • Keeps the specialization in the returned tool response message
  • While allowing the code to populate raw_answer/answer_reasoning in a normal flow

@jamesbraza jamesbraza self-assigned this Aug 26, 2025
@jamesbraza jamesbraza added the bug Something isn't working label Aug 26, 2025
Copilot AI review requested due to automatic review settings August 26, 2025 03:54
@dosubot dosubot bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Aug 26, 2025
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes an issue where the EmptyDocsError failover in gen_answer was leaving raw_answer blank in the PQASession. The changes ensure that when no papers are available, the answer generation process still populates these fields through the normal flow while maintaining specialized error messages in tool responses.

Key changes:

  • Removes early return from gen_answer tool when no docs are present
  • Updates answer generation logic to handle empty contexts with specific error messages
  • Refactors test to properly verify tool response content

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
src/paperqa/agents/tools.py Removes early EmptyDocsError check to allow normal flow processing
src/paperqa/docs.py Updates empty context detection and error message formatting
src/paperqa/prompts.py Adds constant for measuring empty context length
tests/test_agents.py Refactors test to spy on tool responses instead of mocking dependencies

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@jamesbraza jamesbraza force-pushed the removing-empty-docs-error branch from 0eedbd8 to dae79ff Compare August 26, 2025 03:57
pre_str=pre_str,
)

if len(context_str.strip()) < 10: # noqa: PLR2004
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given empty context_str is 11-chars, we couldn't hit this case actually

Comment on lines -312 to -313
if not state.docs.docs:
raise EmptyDocsError("Not generating an answer due to having no papers.")
Copy link
Copy Markdown
Collaborator Author

@jamesbraza jamesbraza Aug 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that state.session.raw_answer was left untouched here. This is fine in normal gen_answer use, but is not okay in the truncation's gen_answer failover. So this is a bug this PR fixes

Copy link
Copy Markdown
Collaborator

@mskarlin mskarlin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Aug 26, 2025
@jamesbraza jamesbraza merged commit 097ccd2 into main Aug 26, 2025
5 checks passed
@jamesbraza jamesbraza deleted the removing-empty-docs-error branch August 26, 2025 16:44
@dosubot
Copy link
Copy Markdown

dosubot bot commented Aug 26, 2025

Documentation updates
Checked 1 published document(s). No updates required.

How did I do? Any feedback?  Join Discord

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working lgtm This PR has been approved by a maintainer size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants