Skip to content

fix: use SkipJsonSchema to exclude callable fields from JSON schema generation#3048

Merged
jlowin merged 6 commits intomainfrom
claude/issue-3046-20260131-2057
Feb 2, 2026
Merged

fix: use SkipJsonSchema to exclude callable fields from JSON schema generation#3048
jlowin merged 6 commits intomainfrom
claude/issue-3046-20260131-2057

Conversation

@strawgate
Copy link
Copy Markdown
Collaborator

Problem

Callable fields on BaseModel classes would break JSON schema generation using Pydantic's model_json_schema() method. This prevented users from:

  • Generating OpenAPI documentation
  • Creating TypeScript types from Python models
  • Using model_json_schema() for introspection
  • Third-party tools that expect valid JSON schemas

Solution

Applied the SkipJsonSchema annotation from pydantic.json_schema to all callable fields across Tools, Resources, Prompts, and ResourceTemplates. This is the Pydantic 2 recommended approach for fields that should not appear in generated schemas, as it only affects JSON schema generation while leaving runtime behavior unchanged.

Added comprehensive test coverage to verify JSON schema generation works correctly for all affected classes.

Fixes #3046

Generated with Claude Code

…eneration

Callable fields on BaseModel classes (tools, resources, prompts, etc.) would
break JSON schema generation using Pydantic's model_json_schema() method.

This fix applies the SkipJsonSchema annotation from pydantic.json_schema to
all callable fields:
- Tool.serializer
- Tool.auth, Resource.auth, Prompt.auth, ResourceTemplate.auth
- FunctionTool.fn
- TransformedTool.fn, parent_tool, forwarding_fn
- FunctionResource.fn
- FunctionResourceTemplate.fn
- FunctionPrompt.fn

SkipJsonSchema is the Pydantic 2 recommended approach for fields that should
not appear in generated schemas, as it only affects JSON schema generation
while leaving runtime behavior unchanged.

Fixes #3046

Co-authored-by: Bill Easton <strawgate@users.noreply.github.com>
@marvin-context-protocol marvin-context-protocol Bot added bug Something isn't working. Reports of errors, unexpected behavior, or broken functionality. tests labels Jan 31, 2026
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jan 31, 2026

Walkthrough

This PR systematically wraps callable and serializer field types across multiple model classes with Pydantic's SkipJsonSchema annotation. Affected fields include authentication callables (auth), function references (fn), serializer functions (serializer), and parent tool references (parent_tool) in prompt, resource, tool, and template classes. This wrapping prevents these non-serializable callable types from being included in generated JSON schemas, addressing the inability to produce JSON schemas from models containing callable fields. Runtime behavior remains unchanged.

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The pull request title accurately and concisely summarizes the main change: using SkipJsonSchema to exclude callable fields from JSON schema generation.
Description check ✅ Passed The description clearly explains the problem, solution, and references the linked issue. It covers the main objectives and indicates comprehensive test coverage was added.
Linked Issues check ✅ Passed The PR addresses issue #3046 by applying SkipJsonSchema annotation to callable fields in Tools, Resources, Prompts, and ResourceTemplates, enabling JSON schema generation as required.
Out of Scope Changes check ✅ Passed All changes are directly related to applying SkipJsonSchema wrapper to callable fields across multiple modules to fix JSON schema generation, with no out-of-scope modifications.
Docstring Coverage ✅ Passed Docstring coverage is 80.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch claude/issue-3046-20260131-2057

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@strawgate strawgate requested a review from jlowin January 31, 2026 21:43
@jlowin jlowin merged commit 6fa90fa into main Feb 2, 2026
12 checks passed
@jlowin jlowin deleted the claude/issue-3046-20260131-2057 branch February 2, 2026 02:30
gfortaine pushed a commit to gfortaine/fastmcp that referenced this pull request Feb 4, 2026
…eneration (PrefectHQ#3048)

Co-authored-by: Bill Easton <strawgate@users.noreply.github.com>
Co-authored-by: claude[bot] <41898282+claude[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working. Reports of errors, unexpected behavior, or broken functionality. tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cannot produce json_schema from FastMCP Tool Type

2 participants