Skip to content

feat(core): add helpers to make content block shaped dicts #32072

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

mdrxy
Copy link
Collaborator

@mdrxy mdrxy commented Jul 16, 2025

I envision these being used in partner packages to have a standard implementation for making content block dicts that conform to the expected shape that will eventually be needed for casting.

Without these, making the dicts would be more error-prone (e.g. forgetting required fields which might lead to future issues). Additionally, without these we'd need to constantly refer to the TypedDict definitions to remember the exact structure, required keys, and valid type literals for each block. These have intellisense autocomplete.

This also helps maintainability in case the schema of a block changes, e.g. renaming or nesting a key.

@mdrxy mdrxy requested a review from eyurtsev as a code owner July 16, 2025 21:10
Copy link

vercel bot commented Jul 16, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
langchain ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 16, 2025 9:17pm

@mdrxy mdrxy requested review from ccurme and sydney-runkle July 16, 2025 21:10
Copy link

codspeed-hq bot commented Jul 16, 2025

CodSpeed WallTime Performance Report

Merging #32072 will not alter performance

Comparing mdrxy/content-block-helpers (2af28a4) with standard_outputs (3c19caf)

⚠️ Unknown Walltime execution environment detected

Using the Walltime instrument on standard Hosted Runners will lead to inconsistent data.

For the most accurate results, we recommend using CodSpeed Macro Runners: bare-metal machines fine-tuned for performance measurement consistency.

Summary

✅ 13 untouched benchmarks

Copy link

codspeed-hq bot commented Jul 16, 2025

CodSpeed Instrumentation Performance Report

Merging #32072 will not alter performance

Comparing mdrxy/content-block-helpers (2af28a4) with standard_outputs (3c19caf)

Summary

✅ 14 untouched benchmarks

Copy link
Collaborator

@sydney-runkle sydney-runkle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same with all of the below ones, want to get the return types right

@@ -69,6 +69,26 @@ class TextContentBlock(TypedDict):
"""Citations and other annotations."""


def make_text_block(
text: str, annotations: Optional[list[dict[str, Any]]] = None
) -> dict[str, Any]:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
) -> dict[str, Any]:
) -> TextContentBlock:

@@ -83,6 +103,22 @@ class ToolCallContentBlock(TypedDict):
"""Tool call ID."""


def make_tool_call_block(
tool_call_id: str,
) -> dict[str, Any]:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
) -> dict[str, Any]:
) -> ToolCallContentBlock:

@@ -93,6 +129,22 @@ class ReasoningContentBlock(TypedDict):
"""Reasoning text."""


def make_reasoning_block(
reasoning: Optional[str] = None,
) -> dict[str, Any]:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
) -> dict[str, Any]:
) -> ReasoningContentBlock:

Copy link
Collaborator

@sydney-runkle sydney-runkle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ignore me, this all makes sense. Thanks!

@mdrxy mdrxy closed this Jul 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants