utils.llm.LLMChat._coerce_to_dict_or_list allows misformatted JSONs through
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 78/100
Research direction
Start in tinytroupe/utils/llm.py at _coerce_to_dict_or_list and reproduce the reported call with '[{[}]'. Inspect the enclosing-character check and compare it with genuinely empty dictionary or list responses. Done means malformed JSON is no longer silently returned as an empty result, while valid empty responses still work.
Written by the indexing model from the issue text.
Description
In certain cases (e.g. long JSON generated by gemini-3.5-flash or other models that tend to generate incomplete or misformed objects), function _coerce_to_dict_or_list can allow mismatched JSONs through as if they were empty:
>>> import tinytroupe.utils.llm
>>> tinytroupe.utils.LLMChat._coerce_to_dict_or_list(None, '[{[}]')
{}
This seems to be due to this check in the function:
which only checks for the existence of dictionary enclosing characters, which can happen even within a misformed JSON.
This can result in silent errors such as TinyPersonFactory.sampling_dimensions being empty and therefore all generated agents would have none of the expected attributes.
Possible solutions:
- Add a simple sanity check through length or present characters (a truly empty dictionary response should not have anything other than a
{},[], and maybe a couple of whitespaces). - Replace the character presence check with an equality check
- Dominant language
- Jupyter Notebook
- Stars
- 7.6k
- Forks
- 685
- PR merge metrics
- No merged PRs in 30d
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from microsoft/TinyTroupe
-
Difficulty 3/5 1-2 days Newbie friendliness 48/100
microsoft/TinyTroupe#166 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 48/100
microsoft/TinyTroupe#165 ·
-
enhancement
Difficulty 5/5 Over a week Newbie friendliness 35/100
microsoft/TinyTroupe#147 · 3 comments ·
-
add litellm support Openenhancement
Difficulty 4/5 3-5 days Newbie friendliness 45/100
microsoft/TinyTroupe#134 · 1 comment ·
-
enhancement
Difficulty 4/5 3-5 days Newbie friendliness 35/100
microsoft/TinyTroupe#121 · 3 comments ·
All issues in microsoft/TinyTroupe
Similar issues
-
bug-unconfirmed
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
-
needs-review
Difficulty 1/5 Under an hour Newbie friendliness 88/100
microsoft/ai-agents-for-beginners#754 · 1 comment ·
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
JuliusBrussee/caveman#1102 · 1 comment ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
use-agent-os/agent-os#3263 ·