Skip to content

DOC: Type error when passing FewShotChatMessagePromptTemplate directly into ChatPromptTemplate.fromMessages #8484

@leesungbin

Description

@leesungbin

Checklist

  • I added a very descriptive title to this issue.
  • I included a link to the documentation page I am referring to (if applicable).

Issue with current documentation:

When following the documentation, attempting to pass a FewShotChatMessagePromptTemplate instance directly as an element in the array to ChatPromptTemplate.fromMessages results in a type error. The fromMessages method expects each element to be either a string, a tuple of [role, content], or another compatible message template, but FewShotChatMessagePromptTemplate is not directly accepted as a valid message input. This leads to confusion for users trying to compose prompts with few-shot examples as shown in the current guide.

Steps to reproduce:

  1. Create a FewShotChatMessagePromptTemplate instance (fewShotPrompt).
  2. Attempt to use it directly in ChatPromptTemplate.fromMessages, e.g.:
const finalPrompt = ChatPromptTemplate.fromMessages([
  ["system", "You are a wondrous wizard of math."],
  fewShotPrompt,
  ["human", "{input}"],
]);
  1. Observe the following type error thrown by TypeScript:
error TS2322: Type 'FewShotChatMessagePromptTemplate<any, any>' is not assignable to type 'ChatPromptTemplate<InputValues, string> | BaseMessagePromptTemplateLike'.
  Type 'FewShotChatMessagePromptTemplate<any, any>' is not assignable to type '{ type: MessageType | "user" | "assistant" | "placeholder"; } & BaseMessageFields & Record<string, unknown>'.
    Property 'type' is missing in type 'FewShotChatMessagePromptTemplate<any, any>' but required in type '{ type: MessageType | "user" | "assistant" | "placeholder"; }'.

Expected behavior:
It should be clear in the documentation how to properly integrate few-shot examples into a chat prompt template, and the code examples should not result in type errors.

Actual behavior:
Passing FewShotChatMessagePromptTemplate directly causes a type error, making it unclear how to compose few-shot prompts with other messages.

Suggested fix:
Update the documentation to show the correct way to combine few-shot examples with other prompt messages, ensuring all code examples are type-safe and runnable.

Idea or request for content:

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions