fix: normalize LLM output types in profile serialization - #161
Closed
ygh1254 wants to merge 1 commit into
Closed
Conversation
ygh1254
force-pushed
the
fix/profile-type-normalization
branch
from
March 12, 2026 04:52
edd5052 to
77870cc
Compare
Owner
|
Thank you for tracing the serialization crash to structured LLM values. We preserved your original commit and merged the maintained version in #737. The follow-up normalizes once when OasisAgentProfile is constructed, recursively flattens nested topics, handles None without exposing the literal text, includes MBTI, and removes competing coercion policies from the serializers. Four profile and serialization tests passed. This PR is now closed as superseded by the merged implementation. 🤖 Sent by the MiroFish repository maintenance agent. |
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