Feedback on Coding Logic [closed]
New to Coding – Need Feedback on My Approach I’m new to coding and software development, and I’m working on a project in Python 3.11 that uses Ultravox (a voice AI) to make outbound calls and collect information about cars. (This is a proxy example for privacy reasons.) I am only posting this to know if my logic is sound or if there's a better to solve this issue. I am hoping to solve my data collection / check list issue via built in coding since I find prompting to be unpredictable / unreliable. How the App Works - The calls collect details about a car, including: Manufacturer (Toyota, Ford, BMW) Model (Camry, F-150, Tesla) Year (2020, 2022, 2023) Engine Type (Gasoline, Hybrid, Electric) Transmission (Automatic, Manual,Single-Speed) Drive Train (4x4, AWD, RWD, FWD) Problem with My Initial Approach - I originally used Regex to scan the transcript and check if all required details were collected before ending the call. The output looked like this: Manufacturer: Tesla Model: Plaid Year: Engine Type: Electric Transmission: Drive Train: Dual Motor Since Year and Transmission were missing, the AI would know to ask about them. Issues with this approach: Regex checking caused a 2-second delay, making the call feel unnatural. Some key details were still missing despite being coded to ask for them. New Idea: Boolean Checklist - Instead of running Regex mid-call, I’m thinking of using a simple True/False checklist to track whether a category was collected. Then, I’d run Regex only at the end to verify completeness. Example Boolean Checklist: Manufacturer: True Model: True Year: False Engine Type: True Transmission: False Drive Train: True Concerns & Questions Is this an effective way to track missing data in a real-time call scenario? How can I ensure similar categories aren’t conflated? Example: If the car is Electric, we still need to ask if it’s Single or Dual Motor. Just because it’s Electric doesn’t mean it’s a Tesla. The app sometimes forgets a related subcategory. Example: It asks if the car is Electric and if it has a Single-Speed Transmission, but it forgets to ask if it’s Dual Motor. It sometimes skips completely unrelated categories. Example: It gathers all powertrain info but forgets to ask about leather seats. Would a Boolean Checklist help prevent this? (Code Example Below) # Check if all required information has been collected. # async def check_(transcript: str, tool_state: dict = None) -> tuple[bool, list[str]]: """ Check if all required information has been collected. This function serves as a dual validation layer, combining both tool tracking and transcript analysis to ensure complete and accurate information collection. Args: transcript: The call transcript tool_state: State from the track_info tool containing structured data Returns: tuple[bool, list[str]]: (is_complete, missing_items) """ # Patterns to validate information in transcript validation_patterns = { REGEX PATTERN } # Initialize missing items list missing_items = [] # Check tool state first if available if tool_state: for field in validation_patterns.keys(): if field not in tool_state or not tool_state[field]: missing_items.append(field) # Then check transcript for each item transcript = transcript.lower() for field, pattern in validation_patterns.items(): if not re.search(pattern, transcript, re.IGNORECASE): if field not in missing_items: # Don't add duplicates missing_items.append(field) # If an item is found in either tool_state or transcript, remove it from missing_items if tool_state: missing_items = [item for item in missing_items if item not in tool_state or not re.search(validation_patterns[item], transcript, re.IGNORECASE)] return (len(missing_items) == 0, missing_items)
![Feedback on Coding Logic [closed]](https://cdn.sstatic.net/Sites/softwareengineering/Img/apple-touch-icon@2.png?v=1ef7363febba)
New to Coding – Need Feedback on My Approach
I’m new to coding and software development, and I’m working on a project in Python 3.11 that uses Ultravox (a voice AI) to make outbound calls and collect information about cars. (This is a proxy example for privacy reasons.)
I am only posting this to know if my logic is sound or if there's a better to solve this issue. I am hoping to solve my data collection / check list issue via built in coding since I find prompting to be unpredictable / unreliable.
How the App Works - The calls collect details about a car, including:
- Manufacturer (Toyota, Ford, BMW)
- Model (Camry, F-150, Tesla)
- Year (2020, 2022, 2023)
- Engine Type (Gasoline, Hybrid, Electric)
- Transmission (Automatic, Manual,Single-Speed)
- Drive Train (4x4, AWD, RWD, FWD)
Problem with My Initial Approach - I originally used Regex to scan the transcript and check if all required details were collected before ending the call. The output looked like this:
- Manufacturer: Tesla
- Model: Plaid
- Year:
- Engine Type: Electric
- Transmission:
- Drive Train: Dual Motor
Since Year and Transmission were missing, the AI would know to ask about them.
Issues with this approach:
- Regex checking caused a 2-second delay, making the call feel unnatural.
- Some key details were still missing despite being coded to ask for them.
New Idea: Boolean Checklist - Instead of running Regex mid-call, I’m thinking of using a simple True/False checklist to track whether a category was collected. Then, I’d run Regex only at the end to verify completeness.
Example Boolean Checklist:
- Manufacturer: True
- Model: True
- Year: False
- Engine Type: True
- Transmission: False
- Drive Train: True
Concerns & Questions
- Is this an effective way to track missing data in a real-time call scenario?
- How can I ensure similar categories aren’t conflated? Example: If the car is Electric, we still need to ask if it’s Single or Dual Motor. Just because it’s Electric doesn’t mean it’s a Tesla.
- The app sometimes forgets a related subcategory. Example: It asks if the car is Electric and if it has a Single-Speed Transmission, but it forgets to ask if it’s Dual Motor. It sometimes skips completely unrelated categories. Example: It gathers all powertrain info but forgets to ask about leather seats. Would a Boolean Checklist help prevent this?
(Code Example Below)
# Check if all required information has been collected.
#
async def check_(transcript: str, tool_state: dict = None) -> tuple[bool, list[str]]:
"""
Check if all required information has been collected.
This function serves as a dual validation layer, combining both tool tracking
and transcript analysis to ensure complete and accurate information collection.
Args:
transcript: The call transcript
tool_state: State from the track_info tool containing structured data
Returns:
tuple[bool, list[str]]: (is_complete, missing_items)
"""
# Patterns to validate information in transcript
validation_patterns = {
REGEX PATTERN
}
# Initialize missing items list
missing_items = []
# Check tool state first if available
if tool_state:
for field in validation_patterns.keys():
if field not in tool_state or not tool_state[field]:
missing_items.append(field)
# Then check transcript for each item
transcript = transcript.lower()
for field, pattern in validation_patterns.items():
if not re.search(pattern, transcript, re.IGNORECASE):
if field not in missing_items: # Don't add duplicates
missing_items.append(field)
# If an item is found in either tool_state or transcript, remove it from missing_items
if tool_state:
missing_items = [item for item in missing_items
if item not in tool_state or
not re.search(validation_patterns[item], transcript, re.IGNORECASE)]
return (len(missing_items) == 0, missing_items)