jixiaxue 知识库
evidence · 2026-04-15

T0-3-real-world-04-call-summarizer

/Users/shanfang/Documents/pe/jixiaxuegong/research/提示工程教程/evidence/T0-anthropic/T0-3-real-world-04-call-summarizer.md

来源:https://github.com/anthropics/courses/blob/master/real_world_prompting/04_call_summarizer.ipynb 爬取日期:2026-03-22

Lesson 4: Call transcript summarizer

In this lesson, we’re going to write a complex prompt for a common customer use-case: summarizing. Specifically, we’ll summarize long customer service call transcripts. Our goal is to summarize customer service calls for customer support metrics. We want summaries of complete customer service calls to evaluate the efficacy of our customer support team. This means we’ll exclude calls that have connection issues, language barriers, and other issues that hinder effective summarization.

Let’s imagine we work for Acme Corporation, a company that sells smart home devices. The company handles hundreds of customer service calls daily and needs a way to quickly turn these conversations into useful, structured data.

Some important considerations include:

To help us out, we’ll follow the best practices we described previously:


Understanding the data

We’ll use a variety of simulated customer service call transcripts from Acme Corporation’s smart home device support team.

A short and simple transcript:

call1 = """
Agent: Thank you for calling Acme Smart Home Support. This is Alex. How can I help you?
Customer: Hi, I can't turn on my smart light bulb.
Agent: I see. Have you tried resetting the bulb?
Customer: Oh, no. How do I do that?
Agent: Just turn the power off for 5 seconds, then back on. It should reset.
Customer: Ok, I'll try that. Thanks!
Agent: You're welcome. Call us back if you need further assistance.
"""

A medium-length transcript with an eventual resolution:

call2 = """
Agent: Acme Smart Home Support, this is Jamie. How may I assist you today?
Customer: Hi Jamie, my Acme SmartTherm isn't maintaining the temperature I set. It's set to 72 but the house is much warmer.
Agent: I'm sorry to hear that. Let's troubleshoot. Is your SmartTherm connected to Wi-Fi?
Customer: Yes, the Wi-Fi symbol is showing on the display.
Agent: Great. Let's recalibrate your SmartTherm. Press and hold the menu button for 5 seconds.
Customer: Okay, done. A new menu came up.
Agent: Perfect. Navigate to "Calibration" and press select. Adjust the temperature to match your room thermometer.
Customer: Alright, I've set it to 79 degrees to match.
Agent: Great. Press select to confirm. It will recalibrate, which may take a few minutes. Check back in an hour to see if it's fixed.
Customer: Okay, I'll do that. Thank you for your help, Jamie.
Agent: You're welcome! Is there anything else I can assist you with today?
Customer: No, that's all. Thanks again.
Agent: Thank you for choosing Acme Smart Home. Have a great day!
"""

A longer call with no resolution:

call3 = """
Agent: Thank you for contacting Acme Smart Home Support. This is Sarah. How can I help you today?
Customer: Hi Sarah, I'm having trouble with my Acme SecureHome system. The alarm keeps going off randomly.
Agent: I'm sorry to hear that. Can you tell me when this started happening?
Customer: It started about two days ago. It's gone off three times now, always in the middle of the night.
Agent: I see. Are there any error messages on the control panel when this happens?
Customer: No, I didn't notice any. But I was pretty groggy each time.
Agent: Understood. Let's check a few things. First, can you confirm that all your doors and windows are closing properly?
Customer: Yes, I've checked all of them. They're fine.
Agent: Okay. Next, let's check the battery in your control panel. Can you tell me if the low battery indicator is on?
Customer: Give me a moment... No, the battery indicator looks normal.
Agent: Alright. It's possible that one of your sensors is malfunctioning. I'd like to run a diagnostic, but I'll need to transfer you to our technical team for that. Is that okay?
Customer: Yes, that's fine. I just want this fixed. It's really disruptive.
Agent: I completely understand. I'm going to transfer you now. They'll be able to run a full system diagnostic and hopefully resolve the issue for you.
Customer: Okay, thank you.
Agent: You're welcome. Thank you for your patience, and I hope you have a great rest of your day.
"""

These examples showcase the variety of calls and considerations we need to handle:


A simple version of the prompt

prompt = """
Summarize the following customer service call transcript. Focus on the main issue, how it was resolved, and any required follow-up.

{transcript}
"""

This basic prompt has several limitations:


Adding a system prompt

system = """
You are an expert customer service analyst, skilled at extracting key information from call transcripts and summarizing them in a structured format.
Your task is to analyze customer service call transcripts and generate concise, accurate summaries while maintaining a professional tone.
"""

Structuring our main prompt

We rely on these prompting tips:

The input data

prompt_pt1 = """
Analyze the following customer service call transcript and generate a JSON summary of the interaction:

<transcript>
[INSERT CALL TRANSCRIPT HERE]
</transcript>
"""

Instructions and output format

JSON output structure:

{
  "summary": {
    "customerIssue": "Brief description of the main problem or reason for the call",
    "resolution": "How the issue was addressed or resolved, if applicable",
    "followUpRequired": true/false,
    "followUpDetails": "Description of any necessary follow-up actions, or null if none required"
  },
  "status": "COMPLETE",
  "ambiguities": ["List of any unclear or vague points in the conversation, or an empty array if none"]
}
prompt_pt2 = """
Instructions:
1. Read the transcript carefully.
2. Analyze the transcript, focusing on the main issue, resolution, and any follow-up required.
3. Generate a JSON object summarizing the key aspects of the interaction according to the specified structure.

Important guidelines:
- Confidentiality: Omit all specific customer data like names, phone numbers, and email addresses.
- Character limit: Restrict each text field to a maximum of 100 characters.
- Maintain a professional tone in your summary.

Output format:
Generate a JSON object with the following structure:
<json>
{
  "summary": {
    "customerIssue": "Brief description of the main problem or reason for the call",
    "resolution": "How the issue was addressed or resolved, if applicable",
    "followUpRequired": true/false,
    "followUpDetails": "Description of any necessary follow-up actions, or null if none required"
  },
  "status": "COMPLETE",
  "ambiguities": ["List of any unclear or vague points in the conversation, or an empty array if none"]
}
</json>
"""

Using XML tags and giving Claude room to think

prompt_pt3 = """
Before generating the JSON, please analyze the transcript in <thinking> tags.
Include your identification of the main issue, resolution, follow-up requirements, and any ambiguities.
Then, provide your JSON output in <json> tags.
"""

By asking Claude to put its analysis within <thinking> tags, we’re prompting it to break down its thought process before formulating the final JSON output. This encourages a more thorough and structured approach to analyzing the transcript.


Edge cases

In the real world, we encounter transcripts that perhaps we don’t want to summarize:

Edge case call examples:

wrong_number_call = """
Agent: Acme Smart Home Support, Lisa speaking. How can I help you?
Customer: Is this tech support?
Agent: Yes, this is technical support for Acme Smart Home devices. What can I help you with?
Customer: Sorry, wrong number.
Agent: No problem. Have a nice day.
"""

incomplete_call = """
Agent: Acme Smart Home Support, this is Sarah. How can I assist you today?
Customer: The thing isn't working.
Agent: I'm sorry to hear that. Could you please specify which device you're having trouble with?
Customer: You know, the usual one. Gotta go, bye.
Agent: Wait, I need more infor... [call disconnected]
"""

garbled_call = """
Agent: Thank you for calling Acme Smart Home Support. This is Alex. How may I assist you today?
Customer: [garbled voice]
Agent: Hello? Are you there?
"""

language_barrier_call = """
Agent: Acme Smart Home Support, Sarah speaking. How can I help you today?
Customer: [Speaking in Spanish]
Agent: I apologize, but I don't speak Spanish. Do you speak English?
Customer: [Continues Spanish]
Agent: One moment please, I'll try to get a translator on the line...
"""

Without special handling, these edge cases produce full “COMPLETE” summaries, which would skew our analysis.


Further prompt improvements

Handling insufficient data

We flag edge-case calls by asking the model to output:

{
  "status": "INSUFFICIENT_DATA"
}
new_instructions_addition = """
Insufficient data criteria:
 If either of these conditions are met:
 a) The transcript has fewer than 5 total exchanges, or
 b) The customer's issue is unclear
 c) The call is garbled, incomplete, or is hindered by a language barrier
 Then return ONLY the following JSON:
 {
 "status": "INSUFFICIENT_DATA"
 }
"""

Adding examples

Three example input/output pairs covering:

  1. A complete interaction that does not require follow up
  2. A complete interaction that does require follow up and contains ambiguities
  3. A non-summarizable interaction that contains insufficient data

Our final prompt

system = """
You are an expert customer service analyst, skilled at extracting key information from call transcripts and summarizing them in a structured format.
Your task is to analyze customer service call transcripts and generate concise, accurate summaries while maintaining a professional tone.
"""

prompt = """
Analyze the following customer service call transcript and generate a JSON summary of the interaction:

<transcript>
[INSERT CALL TRANSCRIPT HERE]
</transcript>

<instructions>
1. Read the transcript carefully.
2. Analyze the transcript, focusing on the main issue, resolution, and any follow-up required.
3. Generate a JSON object summarizing the key aspects of the interaction according to the specified structure.

Important guidelines:
- Confidentiality: Omit all specific customer data like names, phone numbers, and email addresses.
- Character limit: Restrict each text field to a maximum of 100 characters.
- Maintain a professional tone in your summary.

Output format:
Generate a JSON object with the following structure:
<json>
{
  "summary": {
    "customerIssue": "Brief description of the main problem or reason for the call",
    "resolution": "How the issue was addressed or resolved, if applicable",
    "followUpRequired": true/false,
    "followUpDetails": "Description of any necessary follow-up actions, or null if none required"
  },
  "status": "COMPLETE",
  "ambiguities": ["List of any unclear or vague points in the conversation, or an empty array if none"]
}
</json>

Insufficient data criteria:
 If any of these conditions are met:
 a) The transcript has fewer than 5 total exchanges
 b) The customer's issue is unclear
 c) The call is garbled, incomplete, or is hindered by a language barrier
 Then return ONLY the following JSON:
 {
 "status": "INSUFFICIENT_DATA"
 }

Examples:
<examples>
1. Complete interaction:
<transcript>
[SmartTherm recalibration example - resolved, no follow-up]
</transcript>
<thinking>...</thinking>
<json>
{
  "summary": {
    "customerIssue": "SmartTherm not maintaining set temperature, showing higher than set 72 degrees",
    "resolution": "Guided customer through SmartTherm recalibration process",
    "followUpRequired": false,
    "followUpDetails": null
  },
  "status": "COMPLETE",
  "ambiguities": []
}
</json>

2. Interaction requiring follow-up:
<transcript>
[SmartCam Wi-Fi connection issue - escalated to technical team]
</transcript>
<thinking>...</thinking>
<json>
{
  "summary": {
    "customerIssue": "Unable to connect new SmartCam to Wi-Fi",
    "resolution": "Initial troubleshooting unsuccessful, issue escalated to technical team",
    "followUpRequired": true,
    "followUpDetails": "Technical team to contact customer within 24 hours for further assistance"
  },
  "status": "COMPLETE",
  "ambiguities": ["Specific error message customer is receiving not mentioned"]
}
</json>

3. Insufficient data:
<transcript>
[Brief, vague call about smart lock not working - customer leaves]
</transcript>
<thinking>
This transcript has fewer than 5 exchanges and the customer's issue is unclear.
</thinking>
<json>
{
  "status": "INSUFFICIENT_DATA"
}
</json>
</examples>
</instructions>

Before generating the JSON, please analyze the transcript in <thinking> tags.
Include your identification of the main issue, resolution, follow-up requirements, and any ambiguities.
Then, provide your JSON output in <json> tags.
"""

Prompt structure overview:

Analyze the following customer service call transcript and generate a JSON summary of the interaction:

<transcript>
[INSERT CALL TRANSCRIPT HERE]
</transcript>

<instructions>
- General instructions and guidelines
- Output JSON format description
- Insufficient data (edge-case) criteria
<examples>
varied example inputs and outputs
</examples>
</instructions>

Before generating the JSON, please analyze the transcript in <thinking> tags.
Include your identification of the main issue, resolution, follow-up requirements, and any ambiguities.
Then, provide your JSON output in <json> tags.

Extracting JSON from the response:

import re

def summarize_call_with_final_prompt(transcript):
    final_prompt = prompt.replace("[INSERT CALL TRANSCRIPT HERE]", transcript)
    response = client.messages.create(
        model="claude-3-sonnet-20240229",
        system=system,
        max_tokens=4096,
        messages=[
            {"role": "user", "content": final_prompt}
        ]
    )
    json_content = re.search(r'<json>(.*?)</json>', response.content[0].text, re.DOTALL)
    if json_content:
        print(json_content.group(1).strip())
    else:
        print("No JSON content found in the response.")

Final test results

Normal calls - Properly summarized with structured JSON:

{
  "summary": {
    "customerIssue": "Unable to turn on smart light bulb",
    "resolution": "Agent guided customer to reset the bulb by cycling power off and on",
    "followUpRequired": false,
    "followUpDetails": null
  },
  "status": "COMPLETE",
  "ambiguities": []
}

Ambiguous calls - Ambiguities correctly identified:

{
  "summary": {
    "customerIssue": "SmartLock not reliably locking automatically or through app, behavior is inconsistent",
    "resolution": "Troubleshooting attempted but incomplete due to lack of model details, customer had to leave",
    "followUpRequired": true,
    "followUpDetails": "Customer to call back for further troubleshooting of SmartLock issue when available"
  },
  "status": "COMPLETE",
  "ambiguities": [
    "Unclear if related SmartTherm issue mentioned",
    "SmartLock model not identified",
    "Customer's contact number not confirmed"
  ]
}

Edge case calls - Correctly flagged as insufficient data:

{
  "status": "INSUFFICIENT_DATA"
}

Summary

This lesson demonstrates comprehensive prompt engineering for a real-world customer service use case:

  1. Starting Simple: A basic prompt for transcript summarization
  2. Adding Structure: System prompts, XML tags, and JSON output formatting
  3. Improving Quality: Clear instructions, character limits, and confidentiality guidelines
  4. Handling Edge Cases: Adding logic to filter out non-summarizable calls
  5. Using Examples: Providing diverse in-context examples to guide the model
  6. Testing Iteratively: Testing at each stage to validate improvements

The final prompt successfully: