Skip to content

BasePrompt

Sub classes

Name Children Inherits
StaticPrompt
llmling.prompts.models
Static prompt defined by message list.
    DynamicPrompt
    llmling.prompts.models
    Dynamic prompt loaded from callable.
      FilePrompt
      llmling.prompts.models
      Prompt loaded from a file.

        Base classes

        Name Children Inherits
        BaseModel
        pydantic.main
        !!! abstract "Usage Documentation"

        â‹” Inheritance diagram

        graph TD
          3854555607["models.BasePrompt"]
          3879467795["main.BaseModel"]
          2751680898["builtins.object"]
          3879467795 --> 3854555607
          2751680898 --> 3879467795

        🛈 DocStrings

        Bases: BaseModel

        Base class for all prompts.

        Source code in src/llmling/prompts/models.py
        class BasePrompt(BaseModel):
            """Base class for all prompts."""
        
            name: str | None = Field(None, exclude=True)
            """Technical identifier (automatically set from config key during registration)."""
        
            description: str
            """Human-readable description of what this prompt does."""
        
            title: str | None = None
            """Title of the prompt."""
        
            arguments: list[PromptParameter] = Field(default_factory=list)
            """List of arguments that this prompt accepts."""
        
            metadata: dict[str, Any] = Field(default_factory=dict)
            """Additional metadata for storing custom prompt information."""
            # messages: list[PromptMessage]
        
            model_config = ConfigDict(extra="forbid", use_attribute_docstrings=True)
        
            def get_messages(self) -> list[PromptMessage]:
                """Get the messages for this prompt."""
                if not hasattr(self, "messages"):
                    msg = f"{self.__class__.__name__} must implement 'messages' attribute"
                    raise NotImplementedError(msg)
                return self.messages  # pyright: ignore  # ty: ignore[invalid-explicit-return]
        
            def validate_arguments(self, provided: dict[str, Any]) -> None:
                """Validate that required arguments are provided."""
                required = {arg.name for arg in self.arguments if arg.required}
                missing = required - set(provided)
                if missing:
                    msg = f"Missing required arguments: {', '.join(missing)}"
                    raise ValueError(msg)
        
            async def format(self, arguments: dict[str, Any] | None = None) -> list[PromptMessage]:
                """Format this prompt with given arguments.
        
                Args:
                    arguments: Optional argument values
        
                Returns:
                    List of formatted messages
        
                Raises:
                    ValueError: If required arguments are missing
                """
                raise NotImplementedError
        
            def to_mcp_prompt(self) -> MCPPrompt:
                """Convert to MCP Prompt."""
                from mcp.types import Prompt as MCPPrompt
        
                if self.name is None:
                    msg = "Prompt name not set. This should be set during registration."
                    raise ValueError(msg)
                args = [arg.to_mcp_argument() for arg in self.arguments]
                return MCPPrompt(name=self.name, description=self.description, arguments=args)
        

        arguments class-attribute instance-attribute

        arguments: list[PromptParameter] = Field(default_factory=list)
        

        List of arguments that this prompt accepts.

        description instance-attribute

        description: str
        

        Human-readable description of what this prompt does.

        metadata class-attribute instance-attribute

        metadata: dict[str, Any] = Field(default_factory=dict)
        

        Additional metadata for storing custom prompt information.

        name class-attribute instance-attribute

        name: str | None = Field(None, exclude=True)
        

        Technical identifier (automatically set from config key during registration).

        title class-attribute instance-attribute

        title: str | None = None
        

        Title of the prompt.

        format async

        format(arguments: dict[str, Any] | None = None) -> list[PromptMessage]
        

        Format this prompt with given arguments.

        Parameters:

        Name Type Description Default
        arguments dict[str, Any] | None

        Optional argument values

        None

        Returns:

        Type Description
        list[PromptMessage]

        List of formatted messages

        Raises:

        Type Description
        ValueError

        If required arguments are missing

        Source code in src/llmling/prompts/models.py
        async def format(self, arguments: dict[str, Any] | None = None) -> list[PromptMessage]:
            """Format this prompt with given arguments.
        
            Args:
                arguments: Optional argument values
        
            Returns:
                List of formatted messages
        
            Raises:
                ValueError: If required arguments are missing
            """
            raise NotImplementedError
        

        get_messages

        get_messages() -> list[PromptMessage]
        

        Get the messages for this prompt.

        Source code in src/llmling/prompts/models.py
        def get_messages(self) -> list[PromptMessage]:
            """Get the messages for this prompt."""
            if not hasattr(self, "messages"):
                msg = f"{self.__class__.__name__} must implement 'messages' attribute"
                raise NotImplementedError(msg)
            return self.messages  # pyright: ignore  # ty: ignore[invalid-explicit-return]
        

        to_mcp_prompt

        to_mcp_prompt() -> Prompt
        

        Convert to MCP Prompt.

        Source code in src/llmling/prompts/models.py
        def to_mcp_prompt(self) -> MCPPrompt:
            """Convert to MCP Prompt."""
            from mcp.types import Prompt as MCPPrompt
        
            if self.name is None:
                msg = "Prompt name not set. This should be set during registration."
                raise ValueError(msg)
            args = [arg.to_mcp_argument() for arg in self.arguments]
            return MCPPrompt(name=self.name, description=self.description, arguments=args)
        

        validate_arguments

        validate_arguments(provided: dict[str, Any]) -> None
        

        Validate that required arguments are provided.

        Source code in src/llmling/prompts/models.py
        def validate_arguments(self, provided: dict[str, Any]) -> None:
            """Validate that required arguments are provided."""
            required = {arg.name for arg in self.arguments if arg.required}
            missing = required - set(provided)
            if missing:
                msg = f"Missing required arguments: {', '.join(missing)}"
                raise ValueError(msg)
        

        :fa-brands-github: Show source on GitHub