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.4.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.4.0-py3-none-any.whl (7.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: automatic_goggles-0.4.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.4.0.tar.gz
Algorithm Hash digest
SHA256 ea40a56a2b55fed8cea37337c5672bad1db47c9a9580b2a2c0366a725484a2fd
MD5 7187a941801af91729391336b1bdc338
BLAKE2b-256 fd44a51945d067cf63a562ac38a36511849546cabbd2c4d08ecb8d437bc06c2c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for automatic_goggles-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4630e90a8eb14fde2152b78abcffabd65e10da7ee7f5b772b5be40df31576a46
MD5 e79271b9a3f250705bda5f35d6805dba
BLAKE2b-256 06752aaefac32270af9b09049f64f2a3fd1aa4d61df6b6c17c5df15b5befc36e

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