langgenius / mineru cannot access local variable 'result_item' #705

Closed
opened 2026-02-16 10:20:14 -05:00 by yindo · 3 comments
Owner

Originally created by @llauren48 on GitHub (Oct 11, 2025).

Self Checks

  • This is only for bug report, if you would like to ask a question, please head to Discussions.
  • I have searched for existing issues Dify issues & Dify Official Plugins, including closed ones.
  • I confirm that I am using English to submit this report (我已阅读并同意 Language Policy).
  • [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:)
  • Please do not modify this template :) and fill in all the required fields.

Dify version

1.9.0

Plugin version

0.5.0

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

mineru version 2.5.4
dify version 1.9.0
mineru pulgin version 0.5.0

process the pdf from uploaded file would occur the error that "cannot access local variable 'result_item' where it is not associated with a value" in the following picture.

✔️ Error log

Image
Originally created by @llauren48 on GitHub (Oct 11, 2025). ### Self Checks - [x] This is only for bug report, if you would like to ask a question, please head to [Discussions](https://github.com/langgenius/dify/discussions/categories/general). - [x] I have searched for existing issues [Dify issues](https://github.com/langgenius/dify/issues) & [Dify Official Plugins](https://github.com/langgenius/dify-official-plugins/issues), including closed ones. - [x] I confirm that I am using English to submit this report (我已阅读并同意 [Language Policy](https://github.com/langgenius/dify/issues/1542)). - [x] [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:) - [x] Please do not modify this template :) and fill in all the required fields. ### Dify version 1.9.0 ### Plugin version 0.5.0 ### Cloud or Self Hosted Self Hosted (Docker) ### Steps to reproduce mineru version 2.5.4 dify version 1.9.0 mineru pulgin version 0.5.0 process the pdf from uploaded file would occur the error that "cannot access local variable 'result_item' where it is not associated with a value" in the following picture. ### ✔️ Error log <img width="1005" height="702" alt="Image" src="https://github.com/user-attachments/assets/eeb8fc9c-c991-45fb-ae02-93b765af104a" />
yindo added the bug label 2026-02-16 10:20:14 -05:00
yindo closed this issue 2026-02-16 10:20:14 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Oct 11, 2025):

Hi @llauren48! I'm Dosu and I’m helping the dify-official-plugins team.

This error happens because in the Mineru plugin's PDF parsing code, the variable result_item is only defined inside a for loop over results.items(). If results is empty (for example, if the Mineru backend returns no results for a PDF), the loop never runs and result_item is never assigned. After the loop, the code tries to yield result_item, which triggers the UnboundLocalError you saw.

To fix this, you can either initialize result_item before the loop, or (preferably) only yield it if it was actually assigned during the loop. For example, you could add a check after the loop:

if 'result_item' in locals():
    yield self.create_json_message({"_result": result_item})

Or, initialize result_item to a default value before the loop. This will prevent the error when results is empty and make the plugin more robust when handling PDFs that produce no output from Mineru.
You can see the relevant code and the cause of the bug here: Mineru plugin parse.py.

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other  Join Discord Share on X

@dosubot[bot] commented on GitHub (Oct 11, 2025): <!-- Greeting --> Hi @llauren48! I'm [Dosu](https://go.dosu.dev/dosubot) and I’m helping the dify-official-plugins team. <!-- Answer --> This error happens because in the Mineru plugin's PDF parsing code, the variable result_item is only defined inside a for loop over results.items(). If results is empty (for example, if the Mineru backend returns no results for a PDF), the loop never runs and result_item is never assigned. After the loop, the code tries to yield result_item, which triggers the UnboundLocalError you saw. To fix this, you can either initialize result_item before the loop, or (preferably) only yield it if it was actually assigned during the loop. For example, you could add a check after the loop: ```python if 'result_item' in locals(): yield self.create_json_message({"_result": result_item}) ``` Or, initialize result_item to a default value before the loop. This will prevent the error when results is empty and make the plugin more robust when handling PDFs that produce no output from Mineru. You can see the relevant code and the cause of the bug here: [Mineru plugin parse.py](https://github.com/langgenius/dify-official-plugins/blob/3d601e27b51b70bc9c332ea7748015f680bafc07/tools/mineru/tools/parse.py). <!-- Dosu Comment Footer --> *To reply, just mention [@dosu](https://go.dosu.dev/dosubot).* --- <sup>How did I do? [Good](https://app.dosu.dev/response-feedback/9f8fd127-7eb1-48d8-849c-7ae34ec94bb5?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/9f8fd127-7eb1-48d8-849c-7ae34ec94bb5?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/9f8fd127-7eb1-48d8-849c-7ae34ec94bb5?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/9f8fd127-7eb1-48d8-849c-7ae34ec94bb5?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/9f8fd127-7eb1-48d8-849c-7ae34ec94bb5?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/9f8fd127-7eb1-48d8-849c-7ae34ec94bb5?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/9f8fd127-7eb1-48d8-849c-7ae34ec94bb5?feedback_type=other)</sup>&nbsp;&nbsp;[![Join Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot)&nbsp;[![Share on X](https://img.shields.io/badge/X-share-black)](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/langgenius/dify-official-plugins/issues/1834)
Author
Owner

@llauren48 commented on GitHub (Oct 11, 2025):

As you can see in the picture, if I use the api to process the same pdf, the response already reply the results. So the error is not caused by the empty results, it may be is the reason of the inside logical error of getting value.

Image

Here is the link for the test pdf: test1.pdf

@llauren48 commented on GitHub (Oct 11, 2025): As you can see in the picture, if I use the api to process the same pdf, the response already reply the results. So the error is not caused by the empty results, it may be is the reason of the inside logical error of getting value. <img width="852" height="738" alt="Image" src="https://github.com/user-attachments/assets/53c2c464-e505-42cf-9668-a9db394ac436" /> Here is the link for the test pdf: [test1.pdf](https://github.com/user-attachments/files/22861845/test1.pdf)
Author
Owner

@dosubot[bot] commented on GitHub (Oct 11, 2025):

You're right—the error isn't caused by empty results. The plugin's code assigns result_item inside a loop over results.items(), but if the loop doesn't run (for example, if the plugin receives an unexpected data structure or the results key is missing), result_item isn't assigned and the error occurs when it's accessed after the loop. Your API test shows the backend returns valid results for the same PDF, so the bug is likely in how the plugin parses or accesses the response, not in the backend or file content.

To fix this, update the plugin code to only yield result_item if it was assigned during the loop. For example, after the loop, check if result_item exists before yielding:

if 'result_item' in locals():
    yield self.create_json_message({"_result": result_item})

Or, initialize result_item to a default value before the loop. This will prevent the error and make the plugin more robust when handling PDFs that produce output from Mineru. You can review the relevant code and logic here: Mineru plugin parse.py.

If you still see the error even when results are present, double-check that the plugin receives the same data structure as the API response. There could be a mismatch in how the response is delivered to the plugin during runtime.

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other  Join Discord Share on X

@dosubot[bot] commented on GitHub (Oct 11, 2025): <!-- Answer --> You're right—the error isn't caused by empty results. The plugin's code assigns `result_item` inside a loop over `results.items()`, but if the loop doesn't run (for example, if the plugin receives an unexpected data structure or the results key is missing), `result_item` isn't assigned and the error occurs when it's accessed after the loop. Your API test shows the backend returns valid results for the same PDF, so the bug is likely in how the plugin parses or accesses the response, not in the backend or file content. To fix this, update the plugin code to only yield `result_item` if it was assigned during the loop. For example, after the loop, check if `result_item` exists before yielding: ```python if 'result_item' in locals(): yield self.create_json_message({"_result": result_item}) ``` Or, initialize `result_item` to a default value before the loop. This will prevent the error and make the plugin more robust when handling PDFs that produce output from Mineru. You can review the relevant code and logic here: [Mineru plugin parse.py](https://github.com/langgenius/dify-official-plugins/blob/3d601e27b51b70bc9c332ea7748015f680bafc07/tools/mineru/tools/parse.py). If you still see the error even when results are present, double-check that the plugin receives the same data structure as the API response. There could be a mismatch in how the response is delivered to the plugin during runtime. <!-- Dosu Comment Footer --> *To reply, just mention [@dosu](https://go.dosu.dev/dosubot).* --- <sup>How did I do? [Good](https://app.dosu.dev/response-feedback/fc9a6165-66d0-4b8d-88b0-404299a4c784?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/fc9a6165-66d0-4b8d-88b0-404299a4c784?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/fc9a6165-66d0-4b8d-88b0-404299a4c784?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/fc9a6165-66d0-4b8d-88b0-404299a4c784?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/fc9a6165-66d0-4b8d-88b0-404299a4c784?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/fc9a6165-66d0-4b8d-88b0-404299a4c784?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/fc9a6165-66d0-4b8d-88b0-404299a4c784?feedback_type=other)</sup>&nbsp;&nbsp;[![Join Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot)&nbsp;[![Share on X](https://img.shields.io/badge/X-share-black)](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/langgenius/dify-official-plugins/issues/1834)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify-official-plugins#705