ANALYSIS TOOL BOX

LLM Integration

SendPromptToAnthropic

Send a templated prompt to a Claude model via LangChain and return its response.

llmainlplanguage-models

Introduction

Reusable prompts — the same instruction filled in with different data each time — are the backbone of most LLM-powered scripts, but wiring up a template, a client, and a parsed response by hand for every call gets repetitive fast. SendPromptToAnthropic wraps that pattern for Claude: give it a prompt template with {placeholder} variables and a dictionary of values to fill them, and it builds the LangChain prompt, sends it to the specified Claude model, and returns the model's response text.

Teaching Note

This function provides a lightweight, templated interface for sending one-off prompts to Anthropic's Claude models without hand-writing LangChain boilerplate each time. It's most useful for scripts and notebooks that need to run the same prompt shape — with different filled-in values — repeatedly, such as batch summarization, extraction, or classification tasks over a list of inputs.

Parameters

ParameterTypeDefaultDescription
prompt_templaterequiredThe prompt text, containing {variable} placeholders that correspond to the keys in user_input.
user_inputrequiredA dictionary mapping each {variable} placeholder name in prompt_template to the text that should be substituted in.
system_message'You are a helpful assistant.'The system-level instruction describing the assistant's persona or role for this request. Defaults to 'You are a helpful assistant.'
anthropic_api_keyNoneYour Anthropic API key. Required — if None, the function raises a ValueError with a link to the Anthropic console.
temperature0.0Sampling temperature controlling response randomness, where 0.0 is most deterministic. Defaults to 0.0.
chat_model_name'claude-3-opus-20240229'The Claude model ID to send the prompt to. Defaults to a legacy Claude 3 Opus snapshot — pass a current model ID (e.g. 'claude-opus-4-8') for new work.
maximum_tokens1000Maximum number of tokens the model may generate in its response. Defaults to 1000.
verboseTrueWhether to print status output while the request runs. Defaults to True.

Returns

The model's response content as a string (or LangChain message content object, depending on the response shape).

Example

python
from analysistoolbox.llm import SendPromptToAnthropic

response = SendPromptToAnthropic(
    prompt_template="Summarize the following customer feedback in one sentence: {feedback}",
    user_input={"feedback": "The onboarding flow was confusing and took too long to get through."},
    anthropic_api_key="sk-ant-...",
    chat_model_name="claude-opus-4-8",
)
print(response)