"requestBody" in custom tool's schema is not working, but shows errors
Self Checks
- [X] This is only for bug report, if you would like to ask a question, please head to Discussions.
- [X] I have searched for existing issues search for existing issues, including closed ones.
- [X] I confirm that I am using English to submit this report (我已阅读并同意 Language Policy).
- [X] [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:)
- [X] Please do not modify this template :) and fill in all the required fields.
Dify version
0.15.0
Cloud or Self Hosted
Cloud
Steps to reproduce
Put the openapi yaml which has "requestBody". e.g. it is a example from https://github.com/langgenius/dify/issues/11479
openapi: 3.0.0
info:
title: fake title
description: API for creating recommended actions
version: 1.0.0
servers:
- url: https://abc.com
paths:
/recommended_actions:
post:
summary: a summary
description: a description
requestBody:
required: true
content:
application/json:
schema:
type: object
properties:
actions:
type: array
items:
type: string
description: ...
tts:
type: string
description: ...
responses:
'200':
description: ... successfully
✔️ Expected Behavior
Save it correctly.
❌ Actual Behavior
It shows "invalid schema: invalid schema: cannot access local variable 'parameter' where it is not associated with a value".
@a-taka Hello there! I'm here to help you with bug reports, answer your questions, and assist you while waiting for a human maintainer. Let's work together to solve the issue you're facing.
The error message "cannot access local variable 'parameter' where it is not associated with a value" suggests that there might be an issue with how the requestBody is being processed in the OpenAPI schema. In Dify version 0.15.0, the validation of the requestBody component is handled in the ApiTool class within the do_http_request method. This method checks for the presence of a requestBody and processes its content, ensuring that required parameters are present and correctly formatted [1].
Here are a few things you can check or try to resolve the issue:
-
Ensure All Required Fields Are Present: Make sure that all required fields specified in your schema are included in the request. The error might occur if a required field is missing.
-
Check for Typographical Errors: Verify that there are no typographical errors in the schema, especially in the
requestBodysection. -
Validate the Schema Format: Use an OpenAPI validator to ensure that your YAML file is correctly formatted according to the OpenAPI 3.0 specification.
-
Review the Code Handling
requestBody: If you have access to the code, review the section in theApiToolclass that handles therequestBodyto ensure it aligns with your schema's structure.
If these steps do not resolve the issue, it might be necessary to further investigate the specific implementation details or consider if there are any known bugs in the version you are using.
To continue talking to Dosu, mention @dosu.
Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Other
This is not a valid openapi schema. If you want to try it out, please refer this https://github.com/crazywoola/dify-tools-worker/blob/main/docs/basic.md for more details.
@crazywoola try with "GetQuotesFromBreakingBad" (json format) from your page, the same error happens. I am sure it worked, so I think this is a bug.
Facing similar issue as well
will take a look tonight
me too , 0.15.0 tool can't find requestBody
same for me i have tried the openapi schema in swagger editor and it worked fine but within Dify the same error message appeared to me
I found that adding the parameters attribute in the POST method seems to pass the validation, which appears to be an issue with code parsing.
paths:
/recommended_actions:
post:
summary: a summary
description: a description
# adding
parameters:
- name: name
requestBody:
required: true
@rosswj Thanks for the workaround. With the parameters attribute, the actual call from the tool works fine like the requestBody?
@rosswj Thanks for the workaround. With the parameters attribute, the actual call from the tool works fine like the requestBody?
yes