Expected mapping type as input to PromptTemplate. Received <class 'str'>. Output is truncated. View as a scrollable element or open in a text editor. Adjust cell output settings... #19706
Replies: 1 comment
-
Hey there @shobhitagnihotri69! Great to see you diving into some exciting challenges with LangChain again. How's the coding journey been treating you since our last adventure? 🚀😄 The error you're encountering, "Expected mapping type as input to PromptTemplate. Received <class 'str'>", is due to the fact that the Here's the relevant part of the code that checks the input type: def _format_prompt_with_error_handling(self, inner_input: Dict) -> PromptValue:
if not isinstance(inner_input, dict):
if len(self.input_variables) == 1:
var_name = self.input_variables[0]
inner_input = {var_name: inner_input}
else:
raise TypeError(
f"Expected mapping type as input to {self.__class__.__name__}. "
f"Received {type(inner_input)}."
) To resolve this error, ensure that when you call the Regarding your question about chaining multiple from langchain_core.prompts.base import BasePromptTemplate
from langchain_core.prompts.pipeline import PipelinePromptTemplate
# Define your custom PromptTemplates
class FirstPromptTemplate(BasePromptTemplate):
# Implementation of the first prompt template
class SecondPromptTemplate(BasePromptTemplate):
# Implementation of the second prompt template
# Create instances of your custom PromptTemplates
first_prompt = FirstPromptTemplate(...)
second_prompt = SecondPromptTemplate(...)
# Define the final prompt template, which will use the outputs of the previous templates
final_prompt = SomeOtherPromptTemplate(...)
# Create the PipelinePromptTemplate
pipeline_prompt = PipelinePromptTemplate(
final_prompt=final_prompt,
pipeline_prompts=[
("first_output", first_prompt),
("second_output", second_prompt),
]
)
# Use the pipeline prompt
formatted_prompt = pipeline_prompt.format(**input_variables) In this example, I hope this helps! If you have any other questions, feel free to ask. Sources
|
Beta Was this translation helpful? Give feedback.
-
Checked other resources
Commit to Help
Example Code
Description
I am using langchain from 4 months , I am facing this problem for chaining prompt template and chain.invoke requierement
System Info
M1 MacBook
Beta Was this translation helpful? Give feedback.
All reactions