Skip to content

fix: make header names python-safe#592

Open
saurabhkoshatwar wants to merge 5 commits intogoogleapis:mainfrom
saurabhkoshatwar:skoshatwar/issue-fix-580
Open

fix: make header names python-safe#592
saurabhkoshatwar wants to merge 5 commits intogoogleapis:mainfrom
saurabhkoshatwar:skoshatwar/issue-fix-580

Conversation

@saurabhkoshatwar
Copy link
Copy Markdown

@saurabhkoshatwar saurabhkoshatwar commented Mar 14, 2026

Fixes #580

Summary

  • Allow Toolbox tools to use parameter/header names that are not valid Python identifiers (e.g. X-Application-ID).
  • Introduce a Python‑safe field name mapping so function signatures and Pydantic models stay valid while preserving the original parameter names over the wire.

Details

  • Sanitize schema parameter names into Python‑safe field names and use those in inspect.Parameter and Pydantic models.
  • Maintain a mapping from Python‑safe names back to original schema names in ToolboxTool so requests still use the exact header/parameter names defined in tools.yaml.

@anubhav756
Copy link
Copy Markdown
Contributor

/gcbrun

@anubhav756
Copy link
Copy Markdown
Contributor

Thanks for the PR @saurabhkoshatwar !

Could you please take a look at the integration test failure?

I'm also thinking if we could add any more integration/unit tests to verify this change. For instance to see if there could still be any validation failures while actually using hyphenated parameters?

@anubhav756 anubhav756 added priority: p2 Moderately-important priority. Fix may not be included in next release. help wanted labels Mar 16, 2026
@anubhav756 anubhav756 force-pushed the skoshatwar/issue-fix-580 branch 2 times, most recently from 99c3383 to 992c3a5 Compare March 25, 2026 06:26
@anubhav756
Copy link
Copy Markdown
Contributor

/gcbrun

@anubhav756
Copy link
Copy Markdown
Contributor

Thanks for the PR @saurabhkoshatwar !

Could you please take a look at the integration test failure?

I'm also thinking if we could add any more integration/unit tests to verify this change. For instance to see if there could still be any validation failures while actually using hyphenated parameters?

@saurabhkoshatwar Bumping this up in case it got missed :)

@anubhav756 anubhav756 force-pushed the skoshatwar/issue-fix-580 branch from 992c3a5 to de80c29 Compare March 27, 2026 21:37
@anubhav756
Copy link
Copy Markdown
Contributor

/gcbrun

@saurabhkoshatwar
Copy link
Copy Markdown
Author

@anubhav756 could you please rerun the tests? Thanks!

@anubhav756 anubhav756 force-pushed the skoshatwar/issue-fix-580 branch from a5305cd to d092006 Compare March 31, 2026 09:56
@anubhav756
Copy link
Copy Markdown
Contributor

/gcbrun

@saurabhkoshatwar saurabhkoshatwar force-pushed the skoshatwar/issue-fix-580 branch from 3ab9bb9 to 8aa416d Compare April 1, 2026 15:13
@anubhav756
Copy link
Copy Markdown
Contributor

/gcbrun

@saurabhkoshatwar saurabhkoshatwar force-pushed the skoshatwar/issue-fix-580 branch from 8aa416d to 610a9ca Compare April 10, 2026 01:21
@saurabhkoshatwar
Copy link
Copy Markdown
Author

@anubhav756, please rerun /gcbrun

@anubhav756
Copy link
Copy Markdown
Contributor

/gcbrun

@anubhav756
Copy link
Copy Markdown
Contributor

@anubhav756, please rerun /gcbrun

@saurabhkoshatwar Done!

@Deeven-Seru
Copy link
Copy Markdown
Contributor

Hi @saurabhkoshatwar , @anubhav756 I was digging into this and I think we might have a validation order issue.

The current approach builds the Pydantic models with safe names (like user_id), but the actual tool invocation still passes the original hyphenated keys (like user-id). Since there’s no alias mapping, model_validate() is going to fail at runtime because it can’t find the underscored fields it’s looking for.

I tested this locally and it breaks as soon as you try to actually call the tool. I think it will be better if we use Pydantic's Field(alias=...) so the model knows how to map the original names to our safe identifiers.

Also, it would be good to add an E2E test case for this—the current unit tests only check that the model can be created, not that it actually validates hyphenated data during a real call.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

priority: p2 Moderately-important priority. Fix may not be included in next release.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MCP Toolbox HTTP Source - Header Parameter don't allow headers with hyphen.

3 participants