Skip to content

[BUG] AttributeError on appending to an existing JSON field #325

@satviksingh835

Description

@satviksingh835

name: 🐛 Bug Report
about: Create a report to help us improve FireForm.
title: "[BUG]: AttributeError when adding multiple values to the same JSON field"
labels: bug
assignees: ''


⚡️ Describe the Bug

In src/llm.py, the add_response_to_json method throws an AttributeError when attempting to add a second value to an already existing key in the parsed JSON dictionary. The code assumes that if the key exists, it is a list and calls .append(). However, the initial value is stored as a string (or extracted scalar), not a list, causing the application to crash with AttributeError: 'str' object has no attribute 'append'.

👣 Steps to Reproduce

  1. Initialize the LLM class from src/llm.py.
  2. Call llm.add_response_to_json("my_field", "first_value"). The internal dictionary becomes {"my_field": "first_value"}.
  3. Call llm.add_response_to_json("my_field", "second_value").
  4. See error: AttributeError: 'str' object has no attribute 'append'.

📉 Expected Behavior

When a second value is added to an existing key, the code should gracefully handle it by converting the existing string value into a list containing both the old and new values, or the initial insertion should automatically instantiate a list.

🖥️ Environment Information

  • OS: macOS
  • Docker/Compose Version: N/A
  • Ollama Model used: mistral (default in main_loop)

📸 Screenshots/Logs

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/src/llm.py", line 102, in add_response_to_json
    self._json[field].append(parsed_value)
AttributeError: 'str' object has no attribute 'append'

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