langgenius / dify

Dify is an open-source LLM app development platform. Dify's intuitive interface combines AI workflow, RAG pipeline, agent capabilities, model management, observability features and more, letting you quickly go from prototype to production.
https://dify.ai
Other
47.74k stars 6.8k forks source link

Custom Tool with POST method: body object seen as "none" and can't pass validation #9025

Open tipani86 opened 5 days ago

tipani86 commented 5 days ago

Self Checks

Dify version

0.8.3

Cloud or Self Hosted

Cloud

Steps to reproduce

  1. Create a custom tool, both as self-developed and deployed API and on the Dify side.
  2. Use an auto-generated OpenAPI schema (from FastAPI) to tell Dify how API works - everything looks fine on the frontend, even the methods and parameters gets populated correctly.
  3. Enter all parameters in test.

image

✔️ Expected Behavior

All parameters pass validation.

❌ Actual Behavior

One parameter, which is in object (dict) format, failed validation. Error message says it shows as none. It doesn't matter if I wrote something else in this parameter value (like integer or string), the validation error will always show as none, like depicted in the screenshot.

dosubot[bot] commented 5 days ago

@tipani86 Hello there! I'm here to help you with bugs, questions, or becoming a contributor. Let's get this issue sorted out together!

The issue you're experiencing with the parameter being interpreted as none during validation might be related to how Dify handles default values for parameters. If the "default" key is not present in the parameter's schema, the default value is set to None [1]. This could be causing the parameter to be interpreted as none regardless of the input you provide.

To address this, ensure that the OpenAPI schema correctly specifies default values for all parameters, or explicitly set the values in your test to avoid relying on defaults. Additionally, verify that the request body is correctly formatted as JSON and that the Content-Type: application/json header is included in your request [2].

To continue talking to Dosu, mention @dosu.

tipani86 commented 5 days ago

@tipani86 Hello there! I'm here to help you with bugs, questions, or becoming a contributor. Let's get this issue sorted out together!

The issue you're experiencing with the parameter being interpreted as none during validation might be related to how Dify handles default values for parameters. If the "default" key is not present in the parameter's schema, the default value is set to None [1]. This could be causing the parameter to be interpreted as none regardless of the input you provide.

To address this, ensure that the OpenAPI schema correctly specifies default values for all parameters, or explicitly set the values in your test to avoid relying on defaults. Additionally, verify that the request body is correctly formatted as JSON and that the Content-Type: application/json header is included in your request [2].

To continue talking to Dosu, mention @dosu.

As can be seen in the provided screenshot, I am filling all the parameters (and all of them are mandatory, not optional, per the schema. So there should not be any default values being in use in the actual call that goes out.

tipani86 commented 5 days ago

Update: For now, I have been able to work around the issue by breaking the inner object of the original field lesson_status into its component parts (like lesson_name and passed) so basically flattened it into the same level as the outer fields. However, this was only because I had access to both sides as the API's developer myself. Had I tried to use some 3rd party API with its field structure locked as such, I would not have been able to work around this issue.