Skip to content

fix(core): Add typing in ChatMessagePromptTemplate.fromTemplate #7874

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

Merged
merged 1 commit into from
Mar 22, 2025

Conversation

gouroujo
Copy link
Contributor

When using the static method fromTemplate, this PR allows the type of the input to be strictly enforced.

When using the following example :

  const chatPrompt = ChatPromptTemplate.fromTemplate<{foo: string, bar: string}>("Hello {foo}, I'm {bar}");
  const messages = await chatPrompt.formatPromptValue({
    foo: "Foo",
    bar: "Bar",
  });

If an input is missing you got a type error Property 'foo' is missing in type '{ bar: string; }' but required in type 'TypedPromptInputValues<{ foo: string; bar: string; }>'

Screenshot 2025-03-21 at 18 19 32

I have reused the declarations found in PromptTemplate.fromTemplate with the eslint-disabled for the banned type Symbol to stay consistent.

Let me know if you have any feedback.

Thanks for the great work !

@dosubot dosubot bot added the size:S This PR changes 10-29 lines, ignoring generated files. label Mar 22, 2025
Copy link

vercel bot commented Mar 22, 2025

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

Name Status Preview Comments Updated (UTC)
langchainjs-docs ✅ Ready (Inspect) Visit Preview Mar 22, 2025 0:39am
1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
langchainjs-api-refs ⬜️ Ignored (Inspect) Mar 22, 2025 0:39am

@dosubot dosubot bot added the auto:nit Small modifications/deletions, fixes, deps or improvements to existing code or docs label Mar 22, 2025
@jacoblee93 jacoblee93 changed the title Add typing in ChatMessagePromptTemplate.fromTemplate fix(core): Add typing in ChatMessagePromptTemplate.fromTemplate Mar 22, 2025
@jacoblee93
Copy link
Collaborator

Thanks! You shouldn't have to do this in most cases but good to allow.

@dosubot dosubot bot added the lgtm PRs that are ready to be merged as-is label Mar 22, 2025
@jacoblee93 jacoblee93 merged commit e2de559 into langchain-ai:main Mar 22, 2025
35 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto:nit Small modifications/deletions, fixes, deps or improvements to existing code or docs lgtm PRs that are ready to be merged as-is size:S This PR changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants