Add log_level parameter to FastMCP errors#4036
Open
daniel-tsiang wants to merge 2 commits intoPrefectHQ:mainfrom
Open
Add log_level parameter to FastMCP errors#4036daniel-tsiang wants to merge 2 commits intoPrefectHQ:mainfrom
daniel-tsiang wants to merge 2 commits intoPrefectHQ:mainfrom
Conversation
a8073fc to
bed316d
Compare
Add suppress_log parameter to FastMCPError and subclasses to skip server-side logging for expected control-flow errors.
Member
|
I don't think suppressing the log is the right remedy here? Perhaps allowing a custom log level override? Otherwise the server has no report that the error took place. |
9 tasks
Author
@jlowin Thanks Jeremiah, great suggestion. I've amended the PR to allow a custom log level override instead. Please can you take another look? |
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.
Description
Closes #4035
Adds
log_levelparameter toFastMCPErrorand all subclasses (ToolError,ResourceError,PromptError, etc.) to control the server-side log level for expected control-flow errors.When building multi-step LLM workflows, errors often represent normal control flow rather than bugs. For example, a tool might raise
ToolError("Model not deployed, call deploy_model first")to guide the LLM's next action. These expected errors create noise in production error monitoring systems (Sentry, DataDog) that typically capture ERROR-level logs. Rather than suppressing logs entirely (losing all visibility), this lets server operators downgrade the log level so the error is still recorded but doesn't trigger alerts.Usage
The error still reaches the LLM client with the full message and is still logged server-side — just at the specified level instead of ERROR.
Implementation
log_level: int = logging.ERRORparameter toFastMCPError.__init__server.pyto uselogger.log(e.log_level, ..., exc_info=True)instead oflogger.exception()sampling/run.pyfor sampling tool errorsfunction_prompt.pydouble-wrappedPromptErrorContribution type
Checklist
uv run prek run --all-filesand all checks pass