{"record":{"id":"729da9261826e199","repo":"openai/openai-python","slug":"cannot-mix-and-match-text-format-with-text-format","errorCode":null,"errorMessage":"Cannot mix and match text.format with text_format","messagePattern":"Cannot mix and match text\\.format with text_format","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"src/openai/resources/responses/responses.py","lineNumber":1232,"sourceCode":"        if (is_given(response_id) or is_given(starting_after)) and len(new_response_args_names) > 0:\n            raise ValueError(\n                \"Cannot provide both response_id/starting_after can't be provided together with \"\n                + \", \".join(new_response_args_names)\n            )\n        tools = _make_tools(tools)\n        if len(new_response_args_names) > 0:\n            if not is_given(input):\n                raise ValueError(\"input must be provided when creating a new response\")\n\n            if not is_given(model):\n                raise ValueError(\"model must be provided when creating a new response\")\n\n            if is_given(text_format):\n                if not text:\n                    text = {}\n\n                if \"format\" in text:\n                    raise TypeError(\"Cannot mix and match text.format with text_format\")\n\n                text = copy(text)\n                text[\"format\"] = _type_to_text_format_param(text_format)\n\n            api_request: partial[Stream[ResponseStreamEvent]] = partial(\n                self.create,\n                input=input,\n                model=model,\n                tools=tools,\n                context_management=context_management,\n                conversation=conversation,\n                include=include,\n                instructions=instructions,\n                max_output_tokens=max_output_tokens,\n                max_tool_calls=max_tool_calls,\n                metadata=metadata,\n                moderation=moderation,\n                parallel_tool_calls=parallel_tool_calls,","sourceCodeStart":1214,"sourceCodeEnd":1250,"githubUrl":"https://github.com/openai/openai-python/blob/9917c6e28e66e90e1227b3d223c06a8c5441515a/src/openai/resources/responses/responses.py#L1214-L1250","documentation":"Raised by Responses.stream() when you supply both the convenience `text_format` argument and a `format` key inside the `text` dict. The SDK would not know which format definition wins, so it rejects the combination with a TypeError. `text_format` is sugar that internally sets text['format'].","triggerScenarios":"client.responses.stream(model=..., input=..., text_format=MyModel, text={'format': {...}}). Only checked when is_given(text_format) and 'format' in text.","commonSituations":"Upgrading from an older pattern where you constructed text={'format': {...}} manually and then adopting the typed text_format helper without removing the old key; merging code samples that use both styles.","solutions":["Remove `format` from the text dict and keep only text_format","Or drop text_format and express the format fully inside text={'format': ...}"],"exampleFix":"// before\nclient.responses.stream(model=\"gpt-4o\", input=\"hi\", text_format=MyModel, text={\"format\": {\"type\": \"json_schema\"}})\n// after\nclient.responses.stream(model=\"gpt-4o\", input=\"hi\", text_format=MyModel)","handlingStrategy":"validation","validationCode":"if is_given(text_format) and text and 'format' in text:\n    raise ValueError('pass either text_format or text[\"format\"], not both')\n# then call client.responses.stream(..., text_format=text_format, text=text)","typeGuard":"def clean_text_arg(text: dict | None, text_format) -> dict | None:\n    if text_format is not None and text:\n        text = {k: v for k, v in text.items() if k != 'format'}\n    return text","tryCatchPattern":"try:\n    client.responses.stream(model=m, input=i, text_format=tf, text=text)\nexcept TypeError as e:\n    if 'text.format' in str(e):\n        text.pop('format', None)\n        client.responses.stream(model=m, input=i, text_format=tf, text=text)\n    else:\n        raise","preventionTips":["Adopt text_format as the single source of truth and delete legacy text['format'] dicts","Lint your codebase for \"format\" keys inside text= arguments","Document one structured-output style for the team"],"tags":["responses","stream","text-format","conflicting-args","python"],"backgroundTag":"conflicting-parameters","analyzedSha":"9917c6e28e66e90e1227b3d223c06a8c5441515a","analyzedAt":"2026-08-28T11:46:34.183Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}