Performance: Partial prompt templates
MEDIUM IMPACT
This concept affects how quickly prompts are prepared and sent to language models, impacting interaction responsiveness.
from langchain.prompts import PromptTemplate base_prompt = PromptTemplate( input_variables=["name", "age", "hobby"], template="My name is {name}, I am {age} years old and I like {hobby}." ) partial_prompt = base_prompt.partial(hobby="reading") # Reuse partial_prompt with fixed hobby, only fill remaining variables
from langchain.prompts import PromptTemplate full_prompt = PromptTemplate( input_variables=["name", "age", "hobby"], template="My name is {name}, I am {age} years old and I like {hobby}." ) # Each time, recreate full prompt with all variables
| Pattern | Template Parsing | String Processing | API Request Prep | Verdict |
|---|---|---|---|---|
| Full prompt rebuilt each time | High (every call) | High (every call) | Moderate | [X] Bad |
| Partial prompt templates reused | Low (once) | Low (only dynamic parts) | Low | [OK] Good |