Skip to content

Commit 78ef382

Browse files
committed
fix: resolve ContentFormatError syntax error and align expected_type/response_format parameter
- Remove dangling code block from _exceptions.py ContentFormatError class that caused IndentationError - Fix _completions.py to pass response_format= instead of expected_type= to ContentFormatError
1 parent 48b3532 commit 78ef382

2 files changed

Lines changed: 1 addition & 14 deletions

File tree

src/openai/_exceptions.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -169,18 +169,6 @@ class ContentFormatError(OpenAIError):
169169

170170
raw_content: str
171171
"""The raw content string returned by the API that failed to parse."""
172-
# Avoid including the full raw_content in the exception message to prevent
173-
# leaking large or sensitive responses into logs/tracebacks. A truncated
174-
# preview is included instead; the full content is available via the
175-
# `raw_content` attribute for debugging purposes.
176-
preview = raw_content
177-
max_preview_length = 200
178-
if len(preview) > max_preview_length:
179-
preview = preview[:max_preview_length] + "... [truncated]"
180-
181-
super().__init__(
182-
f"Could not parse response content as the response did not match the expected format: {error}. "
183-
f"Raw content preview: {preview!r}"
184172

185173
def __init__(self, *, raw_content: str, error: Exception, response_format: object | None = None) -> None:
186174
expected_response_format = _response_format_name(response_format)

src/openai/lib/_parsing/_completions.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,8 +251,7 @@ def _parse_content(response_format: type[ResponseFormatT], content: str) -> Resp
251251

252252
return pydantic.TypeAdapter(response_format).validate_json(content)
253253
except (pydantic.ValidationError, json.JSONDecodeError) as exc:
254-
expected_type = getattr(response_format, "__qualname__", getattr(response_format, "__name__", repr(response_format)))
255-
raise ContentFormatError(raw_content=content, error=exc, expected_type=expected_type) from exc
254+
raise ContentFormatError(raw_content=content, error=exc, response_format=response_format) from exc
256255

257256
raise TypeError(f"Unable to automatically parse response format type {response_format}")
258257

0 commit comments

Comments
 (0)