@@ -22,6 +22,7 @@ class ModelFeatures:
2222 supports_prompt_cache : bool
2323 supports_stop_words : bool
2424 supports_responses_api : bool
25+ force_string_serializer : bool
2526
2627
2728# Pattern tables capturing current behavior. Keep patterns lowercase.
@@ -85,6 +86,18 @@ class ModelFeatures:
8586 "codex-mini-latest" ,
8687]
8788
89+ # Models that require string serializer for tool messages
90+ # These models don't support structured content format [{"type":"text","text":"..."}]
91+ # and need plain strings instead
92+ FORCE_STRING_SERIALIZER_PATTERNS : list [str ] = [
93+ "*deepseek*" ,
94+ "glm*" ,
95+ # kimi-k2-instruct on groq provider requires string serialization
96+ # Pattern contains '/' so it matches against full model string
97+ # (e.g., "groq/kimi-k2-instruct")
98+ "*groq*/kimi-k2-instruct*" ,
99+ ]
100+
88101
89102def get_features (model : str ) -> ModelFeatures :
90103 """Get model features."""
@@ -96,4 +109,5 @@ def get_features(model: str) -> ModelFeatures:
96109 model , SUPPORTS_STOP_WORDS_FALSE_PATTERNS
97110 ),
98111 supports_responses_api = model_matches (model , RESPONSES_API_PATTERNS ),
112+ force_string_serializer = model_matches (model , FORCE_STRING_SERIALIZER_PATTERNS ),
99113 )
0 commit comments