dify - 💡(How to fix) Fix Object of type File is not JSON serializable [2 comments, 3 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
langgenius/dify#35032Fetched 2026-04-15 06:18:29
View on GitHub
Comments
2
Participants
3
Timeline
3
Reactions
1
Author
Timeline (top)
commented ×2labeled ×1

Error Message

When I use an agent to call a workflow tool (publishing the workflow as a tool) with an input parameter of files in a Chat-flow, it reports an error: Object of type File is not JSON serializable

RAW_BUFFERClick to expand / collapse

Self Checks

  • I have read the Contributing Guide and Language Policy.
  • This is only for bug report, if you would like to ask a question, please head to Discussions.
  • I have searched for existing issues search for existing issues, including closed ones.
  • I confirm that I am using English to submit this report, otherwise it will be closed.
  • 【中文用户 & Non English User】请使用英语提交,否则会被关闭 :)
  • Please do not modify this template :) and fill in all the required fields.

Dify version

1.13.3

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

When I use an agent to call a workflow tool (publishing the workflow as a tool) with an input parameter of files in a Chat-flow, it reports an error: Object of type File is not JSON serializable

<img width="1328" height="320" alt="Image" src="https://github.com/user-attachments/assets/54227722-1911-4588-91c5-c266391321b4" />

✔️ Expected Behavior

Causes and Solutions

❌ Actual Behavior

No response

extent analysis

TL;DR

The issue can be fixed by ensuring that the File object is properly serialized to JSON before passing it as an input parameter to the workflow tool.

Guidance

  • Verify that the File object is being converted to a JSON-serializable format, such as a base64-encoded string or a JSON object with file metadata.
  • Check the documentation for the workflow tool to see if it supports file inputs and if there are any specific requirements for serializing file objects.
  • Consider using a library or utility function to handle file serialization, such as converting the file to a byte array or a JSON object with file properties.
  • Review the error message and stack trace to determine where the serialization error is occurring and adjust the code accordingly.

Example

import json
import base64

# Assuming 'file' is the File object
file_bytes = file.read()
file_json = {'filename': file.name, 'content': base64.b64encode(file_bytes).decode('utf-8')}

Notes

The exact solution will depend on the specific requirements of the workflow tool and the format of the File object. Additional debugging may be necessary to determine the root cause of the serialization error.

Recommendation

Apply workaround: Modify the code to properly serialize the File object to JSON before passing it as an input parameter to the workflow tool. This will likely involve converting the file to a JSON-serializable format, such as a base64-encoded string or a JSON object with file metadata.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING