fix: strip schema titles via schemars SchemaSettings transform#3366
Merged
laststylebender14 merged 2 commits intoMay 20, 2026
Merged
Conversation
Register RemoveSchemaTitles as a schemars Transform inside SchemaSettings so Rust-generated title fields are stripped at schema generation time, not post-hoc in individual providers. - Add tool_schema_generator() that wraps SchemaSettings with RemoveSchemaTitles - Use generator in ToolDefinition::new() and agent.rs instead of schema_for! - Add RemoveSchemaTitles to existing SchemaSettings in ToolCatalog::schema() - Remove redundant serde serialize_with/deserialize_with overrides on input_schema - Remove without_schema_titles() helper (no longer needed) - Remove strip_schema_titles() post-hoc function - Update snapshots: tool catalog schemas no longer contain title fields - Add tests proving generator-level stripping works end-to-end Co-Authored-By: ForgeCode <noreply@forgecode.dev>
laststylebender14
approved these changes
May 20, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Strip Rust-generated
titlefields from tool schemas at generation time using schemarsSchemaSettingstransforms, rather than post-hoc in every provider or serializer.Context
Fixes #3335. The
#[derive(JsonSchema)]macro emits atitlefield containing the Rust struct name (e.g."title": "FSPatch") for every schema node. These internal type names were being forwarded to LLM provider APIs (Anthropic, OpenAI, Google, Bedrock, Codex), which is confusing and leaks implementation details.The previous approach patched around the problem by stripping titles in individual places: custom
serialize_with/deserialize_withonToolDefinition.input_schema, awithout_schema_titles()call inContext::add_tool, and various provider-specific helpers. This spread the responsibility across many callsites and was fragile.Changes
tool_definition.rs: AddRemoveSchemaTitlesschemarsTransformandtool_schema_generator()— aSchemaGeneratorbuilt fromSchemaSettingswith that transform registered. Schemas generated through this generator never containtitlefields.tool_definition.rs: Removestrip_schema_titles(),serialize_schema_without_titles,deserialize_schema_without_titles, andwithout_schema_titles()— all post-hoc stripping helpers are gone.tool_definition.rs:ToolDefinition::new()andToolDefinition::input_schema()now usetool_schema_generator()/ plain assignment.catalog.rs:ToolCatalog::schema()addsRemoveSchemaTitlesto its existing customSchemaSettings, so all catalog tool schemas are generated title-free.agent.rs: Agent tool schema usestool_schema_generator()instead ofschema_for!.context.rs:Context::add_toolreverted to a plainpush— no morewithout_schema_titles()call needed.titlefields.tool_schema_generator()strips titles at the root and recursively in nested schemas, and that round-trip serialization preserves the absence of titles.Key Implementation Details
schemars
SchemaSettingshas atransforms: Vec<Box<dyn GenTransform>>field. AnyTransformpushed there is applied to every schema produced by the resultingSchemaGenerator(viainto_root_schema_for::<T>()).RemoveSchemaTitlesimplementsTransformby removing the"title"key and then callingtransform_subschemasto recurse. This is the idiomatic schemars way to post-process generated schemas globally.Testing
Links