identify error line in following file - ERROR [src.utils.deep_research] Deep research…
- User
identify error line in following file - ERROR [src.utils.deep_research] Deep research Error: string indices must be integers, not 'str' -
- Assistant
The error is raised when the code tries to access a key on a value that’s actually a plain string rather than a dictionary. In this file it occurs at the line:
query_plan = ai_query_content["plan"]
Here, after calling:
ai_query_content = json.loads(ai_query_content)
the code assumes that the result is a dictionary. However, if the repaired JSON isn’t in the expected format (for example, if it remains a string), then trying to use the string key "plan" triggers the “string indices must be integers, not 'str'” error.
- User
suggest fix
- Assistant
One solution is to ensure that the output from repair_json is actually a JSON object before trying to access keys. For example, you could modify the code like this:
────────────────────────────────────────────────────────────────────
pythonCopyai_query_content = ai_query_msg.content.replace("
json", "").replace("", "") ai_query_content = repair_json(ai_query_content)Ensure we have a dict, even if repair_json returns a string
if isinstance(ai_query_content, try: ai_query_data = json.loads(ai_query_content) except Exception as e: logger.error("JSON parsing failed: " + str(e)) raise e
query_plan = ", "") query_tasks = ai_query_data.get("queries", [])
This fix first checks if the repaired content is already a dictionary. If not, it attempts to parse it with json.loads. Using the get() method avoids the “string indices must be integers” error if the JSON structure isn’t as expected. This approach makes the code more robust against unexpected JSON formats.
(Source:github.com)