Skip to content

Instantly share code, notes, and snippets.

@mypy-play
Created November 11, 2025 22:59
Show Gist options
  • Save mypy-play/281d1c7c219f1111b12cb37c05d2d2e5 to your computer and use it in GitHub Desktop.
Save mypy-play/281d1c7c219f1111b12cb37c05d2d2e5 to your computer and use it in GitHub Desktop.
Shared via mypy Playground
from typing import Any, Literal, NotRequired, TypedDict, final
# @final
class InputPromptJSON(TypedDict):
"""JSON format representing the input text to an LLM completion.
This may evolve over time as we add support for tools and other features.
"""
# New rows should always use an array of blocks, even if the application code just gave a string.
# Historical rows may still use a plain string.
system_prompt: str
type: Literal['I']
@final
class S3InputPromptJSON(TypedDict):
"""JSON format representing an s3 reference for the input text to an LLM completion."""
s3_key: str
type: Literal['S']
class Container:
item: InputPromptJSON | S3InputPromptJSON
def f(c: Container) -> None:
item: InputPromptJSON | S3InputPromptJSON = c.item
# if item["type"] == 'S':
if 's3_key' in item:
print(item['s3_key'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment