Skip to content

fix(toolbox-core): Prevent rebinding of parameters in ToolboxTool #186

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 8 commits into from
May 12, 2025

Conversation

anubhav756
Copy link
Contributor

This pull request updates the bind_parameters helper function within the ToolboxTool of the toolbox-core package to enhance parameter binding management.

  • The helper now throws an explicit error if a user attempts to bind a parameter that has already been bound. This change aims to prevent unexpected behavior and improve the clarity of parameter assignments.
  • The error that previously occurred when a user tried to bind a parameter not present in the tool's schema has been removed. This validation will be handled by a strict mode implementation in a future PR.

@anubhav756 anubhav756 self-assigned this Apr 21, 2025
@anubhav756 anubhav756 requested a review from a team as a code owner April 21, 2025 12:44
Copy link
Contributor

@kurtisvg kurtisvg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think the PR matches the behavior we discussed previously.

I think we want the 'default' behavior to be you can't bind a parameter if it doesn't exist. This behavior is the current functionality. This covers "rebinding" of parameters because once a param is bound, it "no longer exists" from the normal parameters perspective.

We discussed a small semantic improvement in the return error -- that if the parameter existed but was already bound, we would return a different error. IMO, this is a low priority.

Separately we discussed potentially needing to implement a strict flag. I thought when we left it we decided to implement the behavior that would error if "any of the parameters provided were attached to exactly 0 tools", and implement that consistently across both the single and group functions.

@anubhav756 anubhav756 force-pushed the anubhav-parse-tool-used branch from 5d59af9 to e841bc1 Compare April 21, 2025 16:17
@anubhav756 anubhav756 force-pushed the anubhav-re-bind-error branch from 92e0f54 to eb5630d Compare April 21, 2025 16:18
@anubhav756
Copy link
Contributor Author

anubhav756 commented Apr 22, 2025

I don't think the PR matches the behavior we discussed previously.

I think we want the 'default' behavior to be you can't bind a parameter if it doesn't exist. This behavior is the current functionality. This covers "rebinding" of parameters because once a param is bound, it "no longer exists" from the normal parameters perspective.

We discussed a small semantic improvement in the return error -- that if the parameter existed but was already bound, we would return a different error. IMO, this is a low priority.

Separately we discussed potentially needing to implement a strict flag. I thought when we left it we decided to implement the behavior that would error if "any of the parameters provided were attached to exactly 0 tools", and implement that consistently across both the single and group functions.

Just wanted to clarify my approach here:

You're totally right – the main goal is still the default behavior we discussed: error if you try to bind a parameter that doesn't exist. That core logic eventually isn't changing.

The reason it might look different in this PR is I was in the middle of moving this "parameter existence" check.

The plan is to shift it from the bind_parameters helper into the ToolboxTool constructor.

This is based on our offline chat (link) about making __init__ consistently error if any specified param exists in zero tools.

So, this PR was just removing the check from bind_parameters as step 1. For now, to ensure the check remains active and isn't lost between PRs, I've added it back into bind_parameters in this current PR. I will then remove it from bind_parameters and simultaneously add it to __init__ of ToolboxTool in a subsequent PR. This way, it will effectively be a "move" of the check from one place to another within a single future PR, rather than removing it now only to add it back later.

Regarding the other check I added in bind_parameters (for trying to re-bind an already-bound parameter):

I put that specific check here because attempting a rebind can only really happen when calling bind_parameters dynamically, not during __init__. So it seemed like the right place for that specific validation.

I can see how it looked like I swapped the high-priority "existence" check for the lower-priority "rebinding" check within this function 🤔. But really, the main existence check will just move to the constructor for consistency, not removed.

The end state will be:

  1. __init__ errors if a param doesn't exist in any tool.
  2. bind_parameters errors if you try to re-bind an existing bound param.

Note

Since these two states are mutually exclusive, I suggest using distinct error messages for each, rather than the same "unable to bind parameters: no parameter named <ARG>" for both, which could be ambiguous.

Hope that clarifies the plan! Let me know if that makes sense or if you have other concerns. 🙂

@anubhav756 anubhav756 force-pushed the anubhav-re-bind-error branch from eb5630d to 8c2ee68 Compare April 29, 2025 10:36
@anubhav756 anubhav756 force-pushed the anubhav-parse-tool-used branch from e841bc1 to 9a0c077 Compare April 29, 2025 10:41
@anubhav756 anubhav756 force-pushed the anubhav-re-bind-error branch from 8c2ee68 to 83eb39a Compare April 29, 2025 10:41
Base automatically changed from anubhav-parse-tool-used to main April 29, 2025 10:54
@anubhav756 anubhav756 force-pushed the anubhav-re-bind-error branch from 83eb39a to a4e9402 Compare April 29, 2025 10:55
@anubhav756 anubhav756 requested a review from kurtisvg April 29, 2025 11:45
@anubhav756 anubhav756 force-pushed the anubhav-re-bind-error branch 3 times, most recently from 9c03dac to f6301bd Compare May 5, 2025 08:24
@anubhav756 anubhav756 closed this May 5, 2025
@anubhav756

This comment was marked as outdated.

@anubhav756 anubhav756 reopened this May 5, 2025
@anubhav756 anubhav756 force-pushed the anubhav-re-bind-error branch from f6301bd to af85f09 Compare May 5, 2025 13:30
@anubhav756 anubhav756 closed this May 5, 2025
@anubhav756 anubhav756 reopened this May 5, 2025
@anubhav756
Copy link
Contributor Author

anubhav756 commented May 5, 2025

Here’s a summary of the updated plan:

We've decided not to introduce the strict flag into the ToolboxTool itself. The primary reason is that methods like add_auth_token_getters and add_bound_params operate on a single tool instance at a time (#205). In this context, a strict flag wouldn't change their behavior – they would operate identically whether the flag was True or False. The complexities around group tools and the strict flag don't apply to these specific ToolboxTool class methods.

This decision has a positive cascading effect:

  1. Since we're not storing or using the strict flag in ToolboxTool, we don't need to pass it to the constructor or these methods.
  2. The validation checks within add_auth_token_getters and add_bound_params become much simpler. We no longer need to replicate or refactor the more complex strict flag logic from the client into ToolboxTool.
    • For add_auth_token_getters, in fix: Add validation to ensure added auth token getters are used by the tool #220 we start leveraging the additional return value from the existing identify_required_authn_params helper from utils, which helps handle the necessary validation and avoids code duplication.
    • For add_bound_params, the primary validation needed is to ensure the parameter exists in the schema. This check is already in place.
  3. The additional check I had previously added to bind_parameters to specifically detect if a parameter was already bound is, as we discussed, a lower priority. The existing check (that the parameter must exist to be bound) implicitly covers this because once a parameter is bound, it's no longer "available" in the same way. However, a more specific error message for re-binding could slightly improve UX.
  4. My original plan to move the "parameter existence" check from bind_parameters into the ToolboxTool constructor (as part of making __init__ error consistently) is no longer necessary. Given the simplified validation (essentially a single-line check to see if a parameter exists in the schema for add_bound_params), it feels like over-engineering to move it. Keeping this straightforward check within add_bound_params is simpler and sufficient for now.

Therefore, with the strict flag being out of scope for ToolboxTool's direct method, we won't be moving this check now.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
This pull request updates the `bind_parameters` helper function within the `ToolboxTool` of the `toolbox-core` package to enhance parameter binding management.

* The helper now throws an explicit error if a user attempts to bind a parameter that has already been bound. This change aims to prevent unexpected behavior and improve the clarity of parameter assignments.
* The error that previously occurred when a user tried to bind a parameter not present in the tool's schema has been removed. This validation will be handled by a `strict` mode implementation in a future PR.
We will remove this once we actually implement the `strict` flag and centralize this functionality by moving this check to the tool's constructor in a future PR.
@anubhav756 anubhav756 force-pushed the anubhav-re-bind-error branch from af85f09 to 574e39f Compare May 12, 2025 11:58
@anubhav756 anubhav756 merged commit 906d0e0 into main May 12, 2025
19 checks passed
@anubhav756 anubhav756 deleted the anubhav-re-bind-error branch May 12, 2025 12:05
@release-please release-please bot mentioned this pull request May 12, 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.

None yet

2 participants