Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:869413421 Ai moive studio Sanitize Prompt Tokens

From Leeroopedia
Knowledge Sources
Domains Architecture, Data_Normalization
Last Updated 2026-10-23 12:00 GMT

Overview

Utility function that normalizes @-mention prompt tokens by replacing presigned media URLs with stable MinIO object keys for durable storage.

Description

sanitize_prompt_tokens_for_storage processes prompt token lists used in canvas @-mentions. For tokens of type mention, it extracts the object key from the nodePreviewUrlSnapshot (a presigned MinIO URL) and stores it as nodePreviewObjectKeySnapshot instead. This ensures stored generation history references remain valid after presigned URLs expire.

The companion function sanitize_resolved_mentions_for_storage performs the same normalization for resolved mention content.

Usage

Called before persisting canvas generation records that contain @-mention tokens with media URLs.

Code Reference

Source Location

Signature

def sanitize_prompt_tokens_for_storage(prompt_tokens: Any) -> List[Dict[str, Any]]:
    """
    Args:
        prompt_tokens: list of token dicts with type, nodePreviewUrlSnapshot, etc.

    Returns:
        Sanitized tokens with nodePreviewObjectKeySnapshot instead of URLs
    """

def sanitize_resolved_mentions_for_storage(resolved_mentions: Any) -> List[Dict[str, Any]]:
    """Sanitize resolved mention content with object key normalization."""

Import

from src.services.canvas import sanitize_prompt_tokens_for_storage

I/O Contract

Inputs

Name Type Required Description
prompt_tokens Any Yes List of token dicts (validated for type)

Outputs

Name Type Description
return value List[Dict] Sanitized tokens; URLs replaced with object keys

Usage Examples

Sanitizing Tokens Before Storage

from src.services.canvas import sanitize_prompt_tokens_for_storage

raw_tokens = [
    {"type": "mention", "nodePreviewUrlSnapshot": "https://minio.../uploads/img.jpg?..."},
    {"type": "text", "content": "a cinematic scene"},
]
sanitized = sanitize_prompt_tokens_for_storage(raw_tokens)
# Result: mention token now has nodePreviewObjectKeySnapshot="uploads/img.jpg"

Related Pages

Implements Principle

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment