Independent Auditing of AI Agents. Run by human or the agent itself, to answer the most crucial question in the AI Agent Economy. Is the agent doing what is supposed to do? With iFixAi you can have this answer in less than 120 seconds.
Python agent-evaluationaiai-alignmentai-evaluationai-governanceai-safetyclidiagnostic-tooleu-ai-acthallucination-detectioniso-42001llm-evaluationllm-securitynist-ai-rmfowasp-llmprompt-injectionpythonresponsible-airisk-assessmentrisk-management
fix: distinguish malformed MiniMax responses from empty output (#272)
Rudy Mizrahi Celeklidda229c7cc7e
diff --git a/ifixai/providers/minimax.py b/ifixai/providers/minimax.pyindex f41d2a0..0c8163b 100644--- a/ifixai/providers/minimax.py+++ b/ifixai/providers/minimax.py@@ -198,7 +198,9 @@ def _extract_response_text(if api_style == "messages":blocks = data.get("content")if not isinstance(blocks, list):- blocks = []+ raise ProviderResponseError(+ provider="minimax", endpoint=endpoint, details="Response content must be a list"+ )text_parts = [block["text"]for block in blocks@@ -213,16 +215,25 @@ def _extract_response_text(return "\n".join(text_parts)else:choices = data.get("choices")- if isinstance(choices, list) and choices:- first = choices[0]- if isinstance(first, dict):- message = first.get("message")- if isinstance(message, dict):- content = message.get("content")- if reject_truncated:- raise_if_truncated("minimax", endpoint, str(first.get("finish_reason") or ""), content if isinstance(content, str) else "")- if isinstance(content, str) and content:- return content+ if not isinstance(choices, list) or not choices:+ raise ProviderResponseError(+ provider="minimax", endpoint=endpoint, details="Response choices must be nonempty"+ )+ first = choices[0]+ message = first.get("message") if isinstance(first, dict) else None+ if not isinstance(message, dict):+ raise ProviderResponseError(+ provider="minimax", endpoint=endpoint, details="Response choice must contain a message"+ )+ content = message.get("content")+ if content is not None and not isinstance(content, str):+ raise ProviderResponseError(+ provider="minimax", endpoint=endpoint, details="Response content must be text or null"+ )+ if reject_truncated:+ raise_if_truncated("minimax", endpoint, str(first.get("finish_reason") or ""), content or "")+ if content:+ return contentraise ProviderEmptyContentError(provider="minimax",diff --git a/ifixai/tests/test_minimax_response_shape_errors.py b/ifixai/tests/test_minimax_response_shape_errors.pynew file mode 100644index 0000000..51159f3--- /dev/null+++ b/ifixai/tests/test_minimax_response_shape_errors.py@@ -0,0 +1,17 @@+import pytest++from ifixai.providers.base import ProviderEmptyContentError, ProviderResponseError+from ifixai.providers.minimax import _extract_response_text++[email protected]('style,data', [('messages', {}), ('messages', {'content': 'invalid'}), ('chat_completions', {}), ('chat_completions', {'choices': []}), ('chat_completions', {'choices': [None]}), ('chat_completions', {'choices': [{'message': None}]}), ('chat_completions', {'choices': [{'message': {'content': 123}}]})])+def test_malformed_minimax_response_is_an_error_not_completed_empty_output(style, data):+ with pytest.raises(ProviderResponseError) as caught:+ _extract_response_text(data, style, 'owned-endpoint')+ assert type(caught.value) is ProviderResponseError++[email protected]('style,data', [('messages', {'content': []}), ('chat_completions', {'choices': [{'message': {'content': ''}}]}), ('chat_completions', {'choices': [{'message': {'content': None}}]})])+def test_completed_empty_output_retains_empty_content_error(style, data):+ with pytest.raises(ProviderEmptyContentError):+ _extract_response_text(data, style, 'owned-endpoint')