Skip to content

UserFilePrompt

🛈 DocStrings

A user prompt referencing a file uploaded via the Anthropic Files API.

Source code in src/clawd_code_sdk/models/prompts.py
@dataclass
class UserFilePrompt:
    """A user prompt referencing a file uploaded via the Anthropic Files API."""

    file_id: str
    """Anthropic file identifier (e.g. 'file_abc123')."""
    title: str | None = None
    """Optional document title."""
    context: str | None = None
    """Optional context about the document."""

    def to_content_block(self) -> BetaRequestDocumentBlockParam:
        """Return the Anthropic API content block dict."""
        block = BetaRequestDocumentBlockParam(
            type="document",
            source=BetaFileDocumentSourceParam(type="file", file_id=self.file_id),
            title=self.title,
            context=self.context,
        )
        return cast(
            "BetaRequestDocumentBlockParam", {k: v for k, v in block.items() if v is not None}
        )

context class-attribute instance-attribute

context: str | None = None

Optional context about the document.

file_id instance-attribute

file_id: str

Anthropic file identifier (e.g. 'file_abc123').

title class-attribute instance-attribute

title: str | None = None

Optional document title.

to_content_block

to_content_block() -> BetaRequestDocumentBlockParam

Return the Anthropic API content block dict.

Source code in src/clawd_code_sdk/models/prompts.py
def to_content_block(self) -> BetaRequestDocumentBlockParam:
    """Return the Anthropic API content block dict."""
    block = BetaRequestDocumentBlockParam(
        type="document",
        source=BetaFileDocumentSourceParam(type="file", file_id=self.file_id),
        title=self.title,
        context=self.context,
    )
    return cast(
        "BetaRequestDocumentBlockParam", {k: v for k, v in block.items() if v is not None}
    )

:fa-brands-github: Show source on GitHub