Skip to content

fix: strip schema titles via schemars SchemaSettings transform#3366

Merged
laststylebender14 merged 2 commits into
mainfrom
fix/strip-schema-titles-via-schemars-transform
May 20, 2026
Merged

fix: strip schema titles via schemars SchemaSettings transform#3366
laststylebender14 merged 2 commits into
mainfrom
fix/strip-schema-titles-via-schemars-transform

Conversation

@amitksingh1490
Copy link
Copy Markdown
Contributor

Summary

Strip Rust-generated title fields from tool schemas at generation time using schemars SchemaSettings transforms, rather than post-hoc in every provider or serializer.

Context

Fixes #3335. The #[derive(JsonSchema)] macro emits a title field 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_with on ToolDefinition.input_schema, a without_schema_titles() call in Context::add_tool, and various provider-specific helpers. This spread the responsibility across many callsites and was fragile.

Changes

  • tool_definition.rs: Add RemoveSchemaTitles schemars Transform and tool_schema_generator() — a SchemaGenerator built from SchemaSettings with that transform registered. Schemas generated through this generator never contain title fields.
  • tool_definition.rs: Remove strip_schema_titles(), serialize_schema_without_titles, deserialize_schema_without_titles, and without_schema_titles() — all post-hoc stripping helpers are gone.
  • tool_definition.rs: ToolDefinition::new() and ToolDefinition::input_schema() now use tool_schema_generator() / plain assignment.
  • catalog.rs: ToolCatalog::schema() adds RemoveSchemaTitles to its existing custom SchemaSettings, so all catalog tool schemas are generated title-free.
  • agent.rs: Agent tool schema uses tool_schema_generator() instead of schema_for!.
  • context.rs: Context::add_tool reverted to a plain push — no more without_schema_titles() call needed.
  • Snapshots: Updated to reflect that tool catalog schemas no longer contain title fields.
  • Tests: New tests verify that 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 SchemaSettings has a transforms: Vec<Box<dyn GenTransform>> field. Any Transform pushed there is applied to every schema produced by the resulting SchemaGenerator (via into_root_schema_for::<T>()). RemoveSchemaTitles implements Transform by removing the "title" key and then calling transform_subschemas to recurse. This is the idiomatic schemars way to post-process generated schemas globally.

Testing

# Run targeted domain tests
cargo test -p forge_domain schema_titles

# Run full domain test suite
cargo insta test -p forge_domain --accept

# Run full workspace
cargo nextest run --all-features --workspace

Links

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>
@github-actions github-actions Bot added the type: fix Iterations on existing features or infrastructure. label May 20, 2026
@amitksingh1490 amitksingh1490 marked this pull request as ready for review May 20, 2026 05:09
@laststylebender14 laststylebender14 merged commit 13941ea into main May 20, 2026
8 checks passed
@laststylebender14 laststylebender14 deleted the fix/strip-schema-titles-via-schemars-transform branch May 20, 2026 05:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: fix Iterations on existing features or infrastructure.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Minimax 2.7 often times use FSPatch instead of the correct tools which is patch

2 participants