fix: normalize LLM output types in profile serialization#161
Open
ygh1254 wants to merge 1 commit into666ghj:mainfrom
Open
fix: normalize LLM output types in profile serialization#161ygh1254 wants to merge 1 commit into666ghj:mainfrom
ygh1254 wants to merge 1 commit into666ghj:mainfrom
Conversation
edd5052 to
77870cc
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
_coerce_to_str,_coerce_to_str_list) to safely convertdict/listLLM outputs into plain stringsOasisAgentProfile.__post_init__— coversbio,persona,country,profession,gender,interested_topics_save_twitter_csv,_save_reddit_json) as a second safety net before string operations like[:150]and.replace()_generate_profile_with_llm()immediately afterjson.loads()to catch structured outputs before they reach the dataclassRoot Cause
LLM JSON parsing (
json.loads) can producedictorlistvalues for fields declared asstr(e.g.bio,persona,country). The serialization code then crashes on string operations like slicing ([:150]) or.replace()applied to non-string types.Traceback from issue:
Testing
The coercion logic handles:
bioasdict→ extracts text via common keys orjson.dumpspersonaasdict→ samecountryaslist→ joins into comma-separated stringinterested_topicsas nested dicts → flattens tolist[str]Closes #154