Skip to content

Fragile keyword matching in render_intro() for time attribute detection #101

@DeveshParagiri

Description

@DeveshParagiri

Problem

render_intro() in extropy/population/persona/renderer.py:282-299 uses hardcoded attribute name matching to detect time-related attributes for formatting:

time_attrs = {"start_time", "departure_time", "arrival_time", "end_time"}
# ...
is_time = any(t in key.lower() for t in time_attrs)
if is_time and 0 <= float(value) <= 24:
    formatted[key] = _format_time(float(value), use_12hr=True)

Silent Failure Cases

Attribute Name Expected Actual Why
departure_time "7:30 AM" "7:30 AM" ✅ Matches
commute_start "7:30 AM" "7.5" ❌ No keywords match
wake_time "6:00 AM" "6" ❌ No keywords match
shift_begins "9:00 AM" "9" ❌ No keywords match
meeting_hour "2:00 PM" "14" ❌ No keywords match
pickup_time "3:30 PM" "15.5" ❌ No keywords match

When the LLM names time attributes differently, they render as raw numbers instead of formatted times, breaking persona immersion.

Suggested Fix

Add a format or display_type field to AttributeSpec:

# population.v1.yaml
attributes:
  - name: commute_start
    type: numeric
    display_format: time_24h  # or time_12h, currency, percentage, etc.

Then in renderer:

if attr.display_format == "time_12h":
    formatted[key] = _format_time(float(value), use_12hr=True)
elif attr.display_format == "time_24h":
    formatted[key] = _format_time(float(value), use_12hr=False)
# etc.

Impact

Low - cosmetic issue in persona rendering, doesn't affect simulation logic.

References

  • extropy/population/persona/renderer.py:282-299
  • time_attrs hardcoded set at line 285

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions