Skip to content

Feedback: guides-task-endpoint-structured-QA

Original URL: https://www.assemblyai.com/docs/guides/task-endpoint-structured-QA
Category: guides
Generated: 05/08/2025, 4:35:37 pm


Generated: 05/08/2025, 4:35:36 pm

Technical Documentation Analysis & Feedback

Section titled “Technical Documentation Analysis & Feedback”

This documentation provides a functional walkthrough but lacks the polish and completeness expected for production developer documentation. The content is more tutorial-like than comprehensive reference material.

1. Missing Prerequisites & Setup Information

Section titled “1. Missing Prerequisites & Setup Information”

Current Problem: Jumps directly into code without proper setup context.

Recommendations:

## Prerequisites
- Python 3.7+ installed
- AssemblyAI account with API key
- Basic familiarity with XML parsing in Python
## Required Dependencies
```bash
pip install assemblyai>=0.17.0
# Set your API key as an environment variable (recommended)
export ASSEMBLYAI_API_KEY="your_api_key_here"
# Or set it in your code (less secure)
import assemblyai as aai
aai.settings.api_key = "your_api_key_here"

Current Problem: Doesn’t explain when/why to use structured Q&A vs other LeMUR endpoints.

Add Section:

## When to Use Structured Q&A
- **Automated reporting**: Extract specific metrics from meeting recordings
- **Compliance auditing**: Ask standardized questions across multiple transcripts
- **Data extraction**: Pull structured information for databases or dashboards
- **Quality assurance**: Ensure consistent answer formats for downstream processing
## Comparison with Other LeMUR Endpoints
| Endpoint | Best For | Output Format |
|----------|----------|---------------|
| Task | Custom prompts, flexible responses | Unstructured text |
| Q&A | Simple questions | Basic text answers |
| **Structured Q&A** | **Multiple questions, consistent formatting** | **Structured XML/JSON** |

Current Problem: No error handling for common failure scenarios.

Add Comprehensive Error Handling:

import assemblyai as aai
import xml.etree.ElementTree as ET
from xml.parsers.expat import ExpatError
def safe_transcribe_and_query(audio_url, questions, max_retries=3):
"""
Safely transcribe audio and run structured Q&A with error handling
"""
try:
# Transcribe with error handling
transcript = aai.Transcriber().transcribe(audio_url)
if transcript.status == aai.TranscriptStatus.error:
raise Exception(f"Transcription failed: {transcript.error}")
# Run LeMUR task with retry logic
for attempt in range(max_retries):
try:
result = transcript.lemur.task(prompt, final_model=aai.LemurModel.claude3_5_sonnet)
return parse_xml_response(result.response)
except Exception as e:
if attempt == max_retries - 1:
raise
print(f"Attempt {attempt + 1} failed: {e}. Retrying...")
except aai.exceptions.AuthenticationError:
raise Exception("Invalid API key. Check your AssemblyAI credentials.")
except aai.exceptions.RateLimitError:
raise Exception("Rate limit exceeded. Please wait before trying again.")
except Exception as e:
raise Exception(f"Unexpected error: {str(e)}")
def parse_xml_response(response_text):
"""Parse XML response with proper error handling"""
try:
clean_response = escape_xml_characters(response_text).strip()
root = ET.fromstring(clean_response)
results = []
for response_elem in root.findall('response'):
question_elem = response_elem.find('question')
answer_elem = response_elem.find('answer')
if question_elem is None or answer_elem is None:
print("Warning: Found response element missing question or answer")
continue
results.append({
'question': question_elem.text or "",
'answer': answer_elem.text or ""
})
return results
except ExpatError as e:
raise Exception(f"Invalid XML response from LeMUR: {e}")
except Exception as e:
raise Exception(f"Failed to parse response: {e}")

Current Problem: Only one basic example with meeting audio.

Add Multiple Examples:

# Example 1: Financial earnings call analysis
financial_questions = [
aai.LemurQuestion(
question="What was the revenue growth percentage?",
answer_format="percentage with one decimal place",
context="Revenue growth compared to previous quarter"
),
aai.LemurQuestion(
question="What were the main growth drivers?",
answer_format="bullet points, maximum 3 items"
),
aai.LemurQuestion(
question="Is the company profitable?",
answer_options=["Yes", "No", "Break-even", "Not mentioned"]
)
]
# Example 2: Customer support call analysis
support_questions = [
aai.LemurQuestion(
question="What was the customer's main issue?",
answer_format="one sentence summary"
),
aai.LemurQuestion(
question="Was the issue resolved?",
answer_options=["Resolved", "Partially resolved", "Unresolved", "Escalated"]
),
aai.LemurQuestion(
question="Customer satisfaction level",
answer_options=["Very satisfied", "Satisfied", "Neutral", "Dissatisfied", "Very dissatisfied", "Not indicated"]
)
]

Current Problem: Doesn’t explain available models or configuration parameters.

Add Configuration Section:

## Configuration Options
### Available Models
```python
# Choose the best model for your use case
models = {
aai.LemurModel.default: "Balanced performance and cost",
aai.LemurModel.claude3_5_sonnet: "Highest accuracy, best for complex analysis",
aai.LemurModel.claude3_haiku: "Fastest responses, good for simple questions"
}
# Usage
result = transcript.lemur.task(prompt, final_model=aai.LemurModel.claude3_haiku)
result = transcript.lemur.task(
prompt,
final_model=aai.LemurModel.claude3_5_sonnet,
max_output_size=3000, # Limit response length
temperature=0.1 # Lower temperature for more consistent responses
)

Current Problem: All code in one block without modular structure.

Provide Modular Structure:

class StructuredQAProcessor:
def __init__(self, api_key):
aai.settings.api_key = api_key
self.transcriber = aai.Transcriber()
def process_audio(self, audio_url, questions, model=aai.LemurModel.claude3_5_sonnet):
"""Complete pipeline from audio to structured answers"""
transcript = self._transcribe(audio_url)
prompt = self._build_prompt(questions)
response = self._query_lemur(transcript, prompt, model)
return self._parse_response(response)
def _transcribe(self, audio_url):
# Implementation with error handling
pass
def _build_prompt(self, questions):
# Implementation
pass
# ... other methods
## Table of Contents
1. [Overview](#overview)
2. [Prerequisites](#prerequisites)
3. [Quick Start](#quick-start)
4. [Step-by-Step Guide](#step-by-step-guide)
5. [Configuration Options](#configuration-options)
6. [Examples](#examples)
7. [Error Handling](#error-handling)
8. [Best Practices](#best-practices)
9
---