A package for extracting structured fields from call transcripts and evaluating conversation quality with confidence scores
Project description
Automatic Goggles
A Python package for extracting structured fields from call transcripts with confidence scores using DSPy and OpenAI's language models.
Features
- Extract structured fields from conversation transcripts
- Evaluate conversation quality with assertion-based scoring
- Contextual field descriptions - Provide detailed descriptions to improve extraction accuracy
- Get confidence scores for extracted data using log probabilities
- Optional reasoning explanations - Control performance and costs with the
include_reasoningflag - Support for multiple field types (currently supports string fields)
- Easy integration with OpenAI API
- Similar functionality to RetellAI post-call processing
Installation
pip install automatic-goggles
Quick Start
from transtype import TranscriptProcessor
# Initialize the processor with your OpenAI API key
processor = TranscriptProcessor(api_key="your-openai-api-key")
# Define your input data
data = {
"messages": [
{
"role": "assistant",
"content": "Hi, this is Marcus, I'm a customer service representative with TechFlow Solutions in Downtown Seattle."
},
{
"role": "user",
"content": "I need to discuss my account billing issues."
}
],
"fields": [
{
"field_name": "representative_name",
"field_type": "string",
"format_example": "Sarah Chen",
"field_description": "The name of the customer service representative or agent who is helping the customer. This should be extracted from their introduction or when they identify themselves during the conversation."
}
]
}
# Process the transcript
result = processor.process(data)
print(result)
Assertion Evaluation
Evaluate conversation quality against specific criteria using the AssertsEvaluator class:
from transtype import AssertsEvaluator
# Initialize evaluator with evaluation steps
evaluator = AssertsEvaluator(
api_key="your-openai-api-key",
evaluation_steps=[
"Did the agent ask for the caller's name?",
"Did the agent offer to help the caller?",
"Was the agent polite and professional?"
],
threshold=0.7
)
# Evaluate conversation (supports both role/content and speaker/text formats)
conversation = {
"messages": [
{"role": "user", "content": "Hi, I need help with my account"},
{"role": "assistant", "content": "Hello! I'd be happy to help. May I have your name?"}
]
}
result = evaluator.evaluate(conversation)
print(result)
# Output: {"result": {"score": 0.85, "success": True, "reason": "..."}}
Field Definitions
Each field to be extracted must include the following properties:
field_name(required): The name/identifier of the field to extractfield_type(required): The data type of the field (currently only "string" is supported)format_example(required): An example of the expected format for this fieldfield_description(required): Detailed context and description to help the AI understand what to extract. The more specific and contextual this description is, the better the extraction accuracy will be.
Note: Starting from version 2.0,
field_descriptionis a required field. If you're upgrading from an earlier version, you'll need to add descriptions to all your existing field definitions.
Example Field Definition
{
"field_name": "customer_phone",
"field_type": "string",
"format_example": "(555) 123-4567",
"field_description": "The customer's phone number mentioned during the call. This could be their primary contact number, callback number, or the number they're calling about. Look for 10-digit phone numbers in various formats."
}
Multiple Field Example
data = {
"messages": [
{
"role": "assistant",
"content": "Hello, this is Sarah from TechSupport. How can I help you today?"
},
{
"role": "user",
"content": "Hi Sarah, I'm having issues with my account. My phone number is 555-123-4567 and my email is john.doe@example.com"
}
],
"fields": [
{
"field_name": "agent_name",
"field_type": "string",
"format_example": "Sarah Chen",
"field_description": "The name of the customer service representative or support agent helping the customer. Usually mentioned in their introduction."
},
{
"field_name": "customer_phone",
"field_type": "string",
"format_example": "(555) 123-4567",
"field_description": "The customer's phone number mentioned during the conversation. Look for 10-digit numbers in formats like 555-123-4567, (555) 123-4567, or 5551234567."
},
{
"field_name": "customer_email",
"field_type": "string",
"format_example": "customer@example.com",
"field_description": "The customer's email address provided during the call. Look for standard email format with @ symbol and domain."
}
]
}
Reasoning Flag
You can control whether to include reasoning explanations in the output using the include_reasoning parameter. This affects both performance and API costs:
With Reasoning (Default)
# Default behavior - includes detailed reasoning
processor = TranscriptProcessor(api_key="your-openai-api-key", include_reasoning=True)
# OR simply:
processor = TranscriptProcessor(api_key="your-openai-api-key")
result = processor.process(data)
# Output includes field_reason with explanation
Without Reasoning (Faster & Cost-Effective)
# Faster processing, lower API costs
processor = TranscriptProcessor(api_key="your-openai-api-key", include_reasoning=False)
result = processor.process(data)
# Output has field_reason set to null
Benefits of disabling reasoning:
- ⚡ Faster processing - Fewer tokens generated
- 💰 Lower costs - Reduced OpenAI API token usage
- 🎯 Focused output - Just the extracted values and confidence scores
When to use each mode:
- With reasoning: When you need explanations for debugging, quality assurance, or transparency
- Without reasoning: For production systems where you only need the extracted values
Output Format
With Reasoning (Default)
{
"fields": [
{
"field_name": "representative_name",
"field_value": "Marcus",
"field_confidence": 0.95,
"field_reason": "Representative introduced himself as 'Marcus' at the beginning of the conversation"
}
]
}
Without Reasoning
{
"fields": [
{
"field_name": "representative_name",
"field_value": "Marcus",
"field_confidence": 0.95,
"field_reason": null
}
]
}
Requirements
- Python 3.8+
- OpenAI API key
License
MIT License
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file automatic_goggles-0.5.0.tar.gz.
File metadata
- Download URL: automatic_goggles-0.5.0.tar.gz
- Upload date:
- Size: 9.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
092988f41dd75fb40296f06b7e9e22147b76b50df44ab35a151e002abf64568b
|
|
| MD5 |
e8fed83c06759bbd6b30c9a68c1e853a
|
|
| BLAKE2b-256 |
01eda80fbe0bf0835381770c1609047659ed857f95352839b9add628b089bfa1
|
File details
Details for the file automatic_goggles-0.5.0-py3-none-any.whl.
File metadata
- Download URL: automatic_goggles-0.5.0-py3-none-any.whl
- Upload date:
- Size: 9.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
18e6c448f8f11c7f2d9710662505e7e16dcf7d968d590ce4ad1388805685ff49
|
|
| MD5 |
7fe67768e77b8074e78b55b6a7fea17b
|
|
| BLAKE2b-256 |
4d147a103b82861cc4a1daea5c6c9bb5c232a56bc9455d126f220b30a6699275
|