Skip to content

Fix prompt return type documentation#2741

Merged
jlowin merged 1 commit intomainfrom
fix-prompt-return-type-docs
Dec 26, 2025
Merged

Fix prompt return type documentation#2741
jlowin merged 1 commit intomainfrom
fix-prompt-return-type-docs

Conversation

@jlowin
Copy link
Copy Markdown
Member

@jlowin jlowin commented Dec 26, 2025

The documentation example for prompts showed returning a single Message object with -> Message, but this is not a supported return type. The convert_result method only handles:

  • str → wrapped as single user Message
  • list[Message | str] → converted to list[Message]
  • PromptResult → passed through

A single Message would raise TypeError: Prompt must return str, list[Message], or PromptResult.

Updated the example to return list[Message] which demonstrates the multi-message capability, and corrected the docstrings in Prompt.from_function and FunctionPrompt.from_function to match the actual supported types.

The docs example showed returning a single Message object, which is not
a supported return type. Updated to show list[Message] and corrected
docstrings in prompt.py to match the actual supported types.
@marvin-context-protocol marvin-context-protocol Bot added bug Something isn't working. Reports of errors, unexpected behavior, or broken functionality. documentation Updates to docs, examples, or guides. Primary change is documentation-related. labels Dec 26, 2025
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Dec 26, 2025

Walkthrough

The pull request updates prompt-related documentation and docstrings to reflect changes in return types. An example function generate_code_request in the prompts documentation was modified to return list[Message] instead of a single Message. The function now returns a two-item messages list comprising the original code message and an assistant follow-up. Additionally, docstrings in src/fastmcp/prompts/prompt.py for Prompt.from_function and FunctionPrompt.from_function were updated to document the new accepted return possibilities, clarifying how different return types (str, list[Message | str], PromptResult) are handled. No functional code changes were made in the source file.

Possibly related PRs

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: fixing documentation for prompt return types to match the actual supported types.
Description check ✅ Passed The description clearly explains the issue, the problem with the current documentation, and what was changed. However, the Contributors Checklist items are not checked off.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ 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 fix-prompt-return-type-docs

📜 Recent review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 61ebc64 and fd7d981.

📒 Files selected for processing (2)
  • docs/servers/prompts.mdx
  • src/fastmcp/prompts/prompt.py
🧰 Additional context used
📓 Path-based instructions (4)
src/fastmcp/**/*.py

📄 CodeRabbit inference engine (AGENTS.md)

src/fastmcp/**/*.py: Python ≥ 3.10 with full type annotations required
Prioritize readable, understandable code - clarity over cleverness. Avoid obfuscated or confusing patterns even if shorter
Follow existing patterns and maintain consistency in code implementation
Be intentional about re-exports - don't blindly re-export everything to parent namespaces. Core types defining a module's purpose should be exported. Specialized features can live in submodules. Only re-export to fastmcp.* for most fundamental types
Never use bare except - be specific with exception types

Files:

  • src/fastmcp/prompts/prompt.py
docs/**/*.mdx

📄 CodeRabbit inference engine (docs/.cursor/rules/mintlify.mdc)

docs/**/*.mdx: Use clear, direct language appropriate for technical audiences
Write in second person ('you') for instructions and procedures in MDX documentation
Use active voice over passive voice in MDX technical documentation
Employ present tense for current states and future tense for outcomes in MDX documentation
Maintain consistent terminology throughout all MDX documentation
Keep sentences concise while providing necessary context in MDX documentation
Use parallel structure in lists, headings, and procedures in MDX documentation
Lead with the most important information using inverted pyramid structure in MDX documentation
Use progressive disclosure in MDX documentation: present basic concepts before advanced ones
Break complex procedures into numbered steps in MDX documentation
Include prerequisites and context before instructions in MDX documentation
Provide expected outcomes for each major step in MDX documentation
End sections with next steps or related information in MDX documentation
Use descriptive, keyword-rich headings for navigation and SEO in MDX documentation
Focus on user goals and outcomes rather than system features in MDX documentation
Anticipate common questions and address them proactively in MDX documentation
Include troubleshooting for likely failure points in MDX documentation
Provide multiple pathways (beginner vs advanced) but offer an opinionated path to avoid overwhelming users in MDX documentation
Always include complete, runnable code examples that users can copy and execute in MDX documentation
Show proper error handling and edge case management in MDX code examples
Use realistic data instead of placeholder values in MDX code examples
Include expected outputs and results for verification in MDX code examples
Test all code examples thoroughly before publishing in MDX documentation
Specify language and include filename when relevant in MDX code examples
Add explanatory comments for complex logic in MDX code examples
Document all API...

Files:

  • docs/servers/prompts.mdx
docs/**/*.{md,mdx,json}

📄 CodeRabbit inference engine (AGENTS.md)

Documentation uses Mintlify framework. Files must be in docs.json to be included. Never modify docs/python-sdk/** (auto-generated)

Files:

  • docs/servers/prompts.mdx
docs/**/*.{md,mdx}

📄 CodeRabbit inference engine (AGENTS.md)

docs/**/*.{md,mdx}: Code examples in documentation must explain before showing code and make blocks fully runnable (include imports)
Documentation structure: Headers form navigation guide with logical H2/H3 hierarchy. Content should be user-focused with sections motivating features (why) before mechanics (how). Use prose over code comments for important information
Never use 'This isn't...' or 'not just...' constructions in writing - state what something IS directly. Avoid defensive writing patterns

Files:

  • docs/servers/prompts.mdx
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: Run tests: Python 3.10 on ubuntu-latest
  • GitHub Check: Run tests: Python 3.13 on ubuntu-latest
  • GitHub Check: Run tests: Python 3.10 on windows-latest
  • GitHub Check: Run tests with lowest-direct dependencies
🔇 Additional comments (3)
src/fastmcp/prompts/prompt.py (2)

244-247: LGTM! Documentation now accurately reflects supported return types.

The docstring correction properly documents the three supported return types and their handling behavior, which matches the actual convert_result implementation (lines 273-307).


386-389: LGTM! Consistent documentation update.

This docstring mirrors the correction in Prompt.from_function and accurately documents the supported return types for function-based prompts.

docs/servers/prompts.mdx (1)

41-48: LGTM! Example corrected to use supported return type.

The example now correctly demonstrates returning list[Message] instead of a single Message object, which aligns with the supported return types documented in the Python file. The multi-message example also better demonstrates the capability to create conversation-style prompts with different roles.


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.

@jlowin jlowin merged commit 70fac26 into main Dec 26, 2025
13 checks passed
@jlowin jlowin deleted the fix-prompt-return-type-docs branch December 26, 2025 03:34
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. documentation Updates to docs, examples, or guides. Primary change is documentation-related.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant