Skip to main content

A package for extracting structured fields from call transcripts 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
  • 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_reasoning flag
  • 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)

Field Definitions

Each field to be extracted must include the following properties:

  • field_name (required): The name/identifier of the field to extract
  • field_type (required): The data type of the field (currently only "string" is supported)
  • format_example (required): An example of the expected format for this field
  • field_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_description is 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

automatic_goggles-0.3.0.tar.gz (7.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

automatic_goggles-0.3.0-py3-none-any.whl (7.9 kB view details)

Uploaded Python 3

File details

Details for the file automatic_goggles-0.3.0.tar.gz.

File metadata

  • Download URL: automatic_goggles-0.3.0.tar.gz
  • Upload date:
  • Size: 7.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.12

File hashes

Hashes for automatic_goggles-0.3.0.tar.gz
Algorithm Hash digest
SHA256 58d9758d6e26be79045519d7d754f2056515121d2abe4a58ad60c9017ccca7c0
MD5 ab9938e524076e8e3564ccc6f608fc71
BLAKE2b-256 5b94132d9ca52da791de72679981e3a3916aafd4db08c8995bdb0f0b85773b5e

See more details on using hashes here.

File details

Details for the file automatic_goggles-0.3.0-py3-none-any.whl.

File metadata

File hashes

Hashes for automatic_goggles-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 67323b24ae20f31b62ff3e613c834bede650b3429047252b7b46f785156cc99a
MD5 f2be0498f9ee0ecb859469e3d9668230
BLAKE2b-256 6393487a8ca0032f2f2b03838fa416bef562de720d4eaa12b9daf987cd5a27ad

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page