Repository: pydantic/pydantic-ai
File: pydantic_ai_slim/pydantic_ai/exceptions.py (Python)

Code before:
        message = f'status_code: {status_code}, model_name: {model_name}, body: {body}'
        super().__init__(model_name=model_name, message=message)


class ContentFilterError(ModelHTTPError):
    """Raised when content filtering is triggered by the model provider."""

    def __init__(self, message: str, status_code: int, model_name: str, body: object | None = None):
        super().__init__(status_code, model_name, body)
        self.message = message


class PromptContentFilterError(ContentFilterError):
    """Raised when the prompt triggers a content filter."""

    def __init__(self, status_code: int, model_name: str, body: object | None = None):
        message = f"Prompt content filtered by model '{model_name}'"
        super().__init__(message, status_code, model_name, body)


class ResponseContentFilterError(ContentFilterError):
    """Raised when the generated response triggers a content filter."""

    def __init__(self, model_name: str, body: object | None = None, status_code: int = 200):
        message = f"Response content filtered by model '{model_name}'"
        super().__init__(message, status_code, model_name, body)


class FallbackExceptionGroup(ExceptionGroup[Any]):
    """A group of exceptions that can be raised when all fallback models fail."""


class ToolRetryError(Exception):
    """Exception used to signal a `ToolRetry` message should be returned to the LLM."""

    def __init__(self, tool_retry: RetryPromptPart):
        self.tool_retry = tool_retry
        super().__init__()


class IncompleteToolCall(UnexpectedModelBehavior):
    """Error raised when a model stops due to token limit while emitting a tool call."""


Review comment (suggestion):
this might seem a bit picky but `Prompt content filtered by the model` doesn't seem right

**Prompt**
please change to `Model '{model_name}' content filter was triggered by the user's prompt`

**Response**
please change to `Model '{model_name}' triggered its content filter while generating a response`

you'll need to update the tests that match the exception string as well



Code after:

    def __init__(self, status_code: int, model_name: str, body: object | None = None):
        self.status_code = status_code
        self.body = body
        message = f'status_code: {status_code}, model_name: {model_name}, body: {body}'
        super().__init__(model_name=model_name, message=message)


class FallbackExceptionGroup(ExceptionGroup[Any]):
    """A group of exceptions that can be raised when all fallback models fail."""


class ToolRetryError(Exception):
    """Exception used to signal a `ToolRetry` message should be returned to the LLM."""

    def __init__(self, tool_retry: RetryPromptPart):
        self.tool_retry = tool_retry
        message = (
            tool_retry.content
            if isinstance(tool_retry.content, str)
            else self._format_error_details(tool_retry.content, tool_retry.tool_name)
        )
        super().__init__(message)

    @staticmethod
    def _format_error_details(errors: list[pydantic_core.ErrorDetails], tool_name: str | None) -> str:
        """Format ErrorDetails as a human-readable message.

        We format manually rather than using ValidationError.from_exception_data because
        some error types (value_error, assertion_error, etc.) require an 'error' key in ctx,
        but when ErrorDetails are serialized, exception objects are stripped from ctx.
        The 'msg' field already contains the human-readable message, so we use that directly.
        """
        error_count = len(errors)
        lines = [
            f'{error_count} validation error{"" if error_count == 1 else "s"}{f" for {tool_name!r}" if tool_name else ""}'
        ]
        for e in errors:
            loc = '.'.join(str(x) for x in e['loc']) if e['loc'] else '__root__'
            lines.append(loc)
            lines.append(f'  {e["msg"]} [type={e["type"]}, input_value={e["input"]!r}]')
        return '\n'.join(lines)


class IncompleteToolCall(UnexpectedModelBehavior):
    """Error raised when a model stops due to token limit while emitting a tool call."""