Skip to content

fix!: Improve response handling from Toolbox server #69

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 18 commits into from
Mar 21, 2025

Conversation

anubhav756
Copy link
Contributor

@anubhav756 anubhav756 commented Feb 27, 2025

  • We remove response.raise_for_status() as it masks error reasons thrown by Toolbox server.

  • We return the value of result key from the response body, so that it can directly be fed to LLMs.

    • This would also prevent situations where the response is:
      { "result": "{ 'some': 'value' }" }
      and when we feed that to LLM by stringifying, it becomes something like:
      { \'result\': "{ \'key\': \'value\' }" }
      which is more cryptic for the LLM because of the extra \ characters due to double stringification.
  • We also check for error in the response and throw a ToolException with the response if applicable.

@anubhav756 anubhav756 self-assigned this Feb 27, 2025
@anubhav756 anubhav756 requested a review from a team as a code owner February 27, 2025 13:44
Earlier we made all fields as optional since we wanted to keep some fields optional for the LLM. Since Toolbox did not support optional fields, there was no way to know which fields were optional, so as a worst-case, we did a temporary workaround of keeping all fields as optional in the schema generated by Toolbox SDK.

Now, there has been some evidence that the LLMs do not work very well with optional parameters, and so we have decided not to support optional fields for now, neither in Toolbox service nor in the SDK.

This PR removes that temporary fix of making all the fields optional.

This PR also removes an augmentation to the request body where `None` values were converted to empty strings (`''`). This is because now that LLM knows no fields are optional, we can be sure that we would not be getting any `None` values as inputs to the tools. So the function `_convert_none_to_empty_string` is not required anymore.
* We remove `response.raise_for_status()` as it masks error reasons thrown by Toolbox server.

* We return the value of `result` key from the response body, so that it can directly be fed to LLMs.
  * This would also prevent situations where the response is `{ "result": '{ "some": "value" }' }` and when we feed that to LLM by stringifying, it becomes something like `"{ "result": '{ \"some\": \"value\" }' }"` which is more cryptic for the LLM because of the extra `\` characters due to double stringification.

* We also check for `error` in the response and throw a `ToolException` with the response if applicable.
Earlier we made all fields as optional since we wanted to keep some fields optional for the LLM. Since Toolbox did not support optional fields, there was no way to know which fields were optional, so as a worst-case, we did a temporary workaround of keeping all fields as optional in the schema generated by Toolbox SDK.

Now, there has been some evidence that the LLMs do not work very well with optional parameters, and so we have decided not to support optional fields for now, neither in Toolbox service nor in the SDK.

This PR removes that temporary fix of making all the fields optional.

This PR also removes an augmentation to the request body where `None` values were converted to empty strings (`''`). This is because now that LLM knows no fields are optional, we can be sure that we would not be getting any `None` values as inputs to the tools. So the function `_convert_none_to_empty_string` is not required anymore.
anubhav756 and others added 3 commits March 10, 2025 20:49
Earlier we made all fields as optional since we wanted to keep some fields optional for the LLM. Since Toolbox did not support optional fields, there was no way to know which fields were optional, so as a worst-case, we did a temporary workaround of keeping all fields as optional in the schema generated by Toolbox SDK.

Now, there has been some evidence that the LLMs do not work very well with optional parameters, and so we have decided not to support optional fields for now, neither in Toolbox service nor in the SDK.

This PR removes that temporary fix of making all the fields optional.

This PR also removes an augmentation to the request body where `None` values were converted to empty strings (`''`). This is because now that LLM knows no fields are optional, we can be sure that we would not be getting any `None` values as inputs to the tools. So the function `_convert_none_to_empty_string` is not required anymore.
anubhav756 and others added 3 commits March 10, 2025 20:51
Earlier we made all fields as optional since we wanted to keep some fields optional for the LLM. Since Toolbox did not support optional fields, there was no way to know which fields were optional, so as a worst-case, we did a temporary workaround of keeping all fields as optional in the schema generated by Toolbox SDK.

Now, there has been some evidence that the LLMs do not work very well with optional parameters, and so we have decided not to support optional fields for now, neither in Toolbox service nor in the SDK.

This PR removes that temporary fix of making all the fields optional.

This PR also removes an augmentation to the request body where `None` values were converted to empty strings (`''`). This is because now that LLM knows no fields are optional, we can be sure that we would not be getting any `None` values as inputs to the tools. So the function `_convert_none_to_empty_string` is not required anymore.
Base automatically changed from anubhav-optional to main March 12, 2025 07:02
@anubhav756 anubhav756 merged commit f4935c0 into main Mar 21, 2025
9 checks passed
@anubhav756 anubhav756 deleted the anubhav-response branch March 21, 2025 19:31
This was referenced Apr 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants