Skip to content

Prompt Errors

Exceptions for prompt management operations.

Error Hierarchy

PromptError (base)
├── PromptNotFoundError
├── TemplateRenderError
├── TemplateValidationError
├── MarkdownParseError
└── TemplateConflictError

PromptError

Base exception for all prompt-related errors.

from mamba_agents.prompts import PromptError

try:
    # Any prompt operation
    pass
except PromptError as e:
    print(f"Prompt error: {e}")

PromptNotFoundError

Raised when a template cannot be found.

from mamba_agents.prompts import PromptManager, PromptNotFoundError

manager = PromptManager()

try:
    prompt = manager.render("nonexistent/template")
except PromptNotFoundError as e:
    print(f"Template not found: {e.name}")
    print(f"Version: {e.version}")

Attributes

Attribute Type Description
name str Template name that was not found
version str | None Version that was requested

TemplateRenderError

Raised when a template fails to render.

from mamba_agents.prompts import PromptManager, TemplateRenderError, PromptConfig

# With strict mode
config = PromptConfig(strict_mode=True)
manager = PromptManager(config=config)
manager.register("test", "Hello {{ name }}")

try:
    # Missing required variable
    prompt = manager.render("test")
except TemplateRenderError as e:
    print(f"Render failed for: {e.name}")
    print(f"Cause: {e.cause}")

Attributes

Attribute Type Description
name str Template name that failed to render
cause Exception Underlying exception

TemplateValidationError

Raised when a template has invalid syntax.

from mamba_agents.prompts import PromptTemplate, TemplateValidationError

try:
    template = PromptTemplate(
        name="invalid",
        version="v1",
        source="{% if unclosed",  # Invalid syntax
    )
    template.render()
except TemplateValidationError as e:
    print(f"Invalid template: {e.name}")

Attributes

Attribute Type Description
name str Template name with invalid syntax

MarkdownParseError

Raised when a Markdown template's YAML frontmatter is malformed.

from mamba_agents.prompts import PromptManager, MarkdownParseError

manager = PromptManager()

try:
    # Template with invalid YAML frontmatter
    prompt = manager.render("system/invalid_yaml")
except MarkdownParseError as e:
    print(f"Parse failed for: {e.name}")

Attributes

Attribute Type Description
name str Template name that failed to parse

TemplateConflictError

Raised when both .jinja2 and .md files exist for the same template name.

from mamba_agents.prompts import PromptManager, TemplateConflictError

manager = PromptManager()

try:
    # Both assistant.jinja2 and assistant.md exist in prompts/v1/system/
    prompt = manager.render("system/assistant")
except TemplateConflictError as e:
    print(f"Conflicting files for: {e.name}")
    print(f"Version: {e.version}")
    print(f"Extensions found: {e.extensions}")  # ['.jinja2', '.md']

Attributes

Attribute Type Description
name str Template name with conflicting files
version str Version where conflict was found
extensions list[str] List of conflicting file extensions

API Reference

errors

Prompt management exceptions.

PromptError

Bases: Exception

Base exception for prompt-related errors.

PromptNotFoundError

PromptNotFoundError(name: str, version: str | None = None)

Bases: PromptError

Raised when a prompt template cannot be found.

Initialize the error.

PARAMETER DESCRIPTION
name

Template name that was not found.

TYPE: str

version

Template version that was not found.

TYPE: str | None DEFAULT: None

Source code in src/mamba_agents/prompts/errors.py
def __init__(self, name: str, version: str | None = None) -> None:
    """Initialize the error.

    Args:
        name: Template name that was not found.
        version: Template version that was not found.
    """
    self.name = name
    self.version = version
    version_str = f" (version: {version})" if version else ""
    super().__init__(f"Prompt template not found: {name}{version_str}")

TemplateRenderError

TemplateRenderError(name: str, cause: Exception)

Bases: PromptError

Raised when a template fails to render.

Initialize the error.

PARAMETER DESCRIPTION
name

Template name that failed to render.

TYPE: str

cause

The underlying exception.

TYPE: Exception

Source code in src/mamba_agents/prompts/errors.py
def __init__(self, name: str, cause: Exception) -> None:
    """Initialize the error.

    Args:
        name: Template name that failed to render.
        cause: The underlying exception.
    """
    self.name = name
    self.cause = cause
    super().__init__(f"Failed to render template '{name}': {cause}")

TemplateValidationError

TemplateValidationError(name: str, message: str)

Bases: PromptError

Raised when a template has invalid syntax or structure.

Initialize the error.

PARAMETER DESCRIPTION
name

Template name with invalid syntax.

TYPE: str

message

Description of the validation error.

TYPE: str

Source code in src/mamba_agents/prompts/errors.py
def __init__(self, name: str, message: str) -> None:
    """Initialize the error.

    Args:
        name: Template name with invalid syntax.
        message: Description of the validation error.
    """
    self.name = name
    super().__init__(f"Invalid template '{name}': {message}")

MarkdownParseError

MarkdownParseError(name: str, message: str)

Bases: PromptError

Raised when a markdown prompt fails to parse.

This typically occurs when the YAML frontmatter is malformed.

Initialize the error.

PARAMETER DESCRIPTION
name

Template name that failed to parse.

TYPE: str

message

Description of the parse error.

TYPE: str

Source code in src/mamba_agents/prompts/errors.py
def __init__(self, name: str, message: str) -> None:
    """Initialize the error.

    Args:
        name: Template name that failed to parse.
        message: Description of the parse error.
    """
    self.name = name
    super().__init__(f"Failed to parse markdown prompt '{name}': {message}")

TemplateConflictError

TemplateConflictError(
    name: str, version: str, extensions: list[str]
)

Bases: PromptError

Raised when multiple template files exist for the same name.

For example, both 'prompt.md' and 'prompt.jinja2' exist.

Initialize the error.

PARAMETER DESCRIPTION
name

Template name with conflicting files.

TYPE: str

version

Template version where conflict was found.

TYPE: str

extensions

List of conflicting file extensions.

TYPE: list[str]

Source code in src/mamba_agents/prompts/errors.py
def __init__(self, name: str, version: str, extensions: list[str]) -> None:
    """Initialize the error.

    Args:
        name: Template name with conflicting files.
        version: Template version where conflict was found.
        extensions: List of conflicting file extensions.
    """
    self.name = name
    self.version = version
    self.extensions = extensions
    ext_list = ", ".join(extensions)
    super().__init__(
        f"Multiple template files found for '{name}' (version: {version}): {ext_list}"
    )