Skip to content

fix: tolerate raw tool-call entries in precontext (#1) - #7

Merged
Khurdhula-Harshavardhan merged 3 commits into
mainfrom
fix/precontext-strict-validation
Jul 20, 2026
Merged

fix: tolerate raw tool-call entries in precontext (#1)#7
Khurdhula-Harshavardhan merged 3 commits into
mainfrom
fix/precontext-strict-validation

Conversation

@Abhinavexist

@AbhinavexistAbhinavexist commented Jul 17, 2026

Copy link
Copy Markdown
Collaborator

Issue: #1

Fix. Make Precontext lenient (name: Optional[str] = None, model_config = ConfigDict(extra="allow")), mirroring openai-python's type strongly, validate loosely, preserve everything:

  • re-validation never raises on a tool-call turn;
  • well-formed entries stay typed (p.name / p.result);
  • raw tool-call entries are preserved (p.model_extra["toolName"], etc.);
  • typed choices / message are unaffected (kept model_validate, not a lossy model_construct).

Tests. Added a mixed-precontext fixture (MIXED_PRECONTEXT: one {name,result} + one raw {toolCallId,toolName,input}) and a regression test test_precontext_tolerates_raw_toolcall_entries. The reporter's exact repro now returns without error. ruff / mypy --strict / pytest (25) all green.

Abhinavexistand others added 3 commits July 18, 2026 02:15
`to_interfaze` re-validated the completion through a strict `Precontext`
(name required), but the server appends raw model tool-calls
`{toolCallId, toolName, input}` to `precontext` on any tool / run_code turn
— no `name`/`result` — so `create()` raised `ValidationError` on those turns.
Make `Precontext` lenient (optional `name`, `extra="allow"`), mirroring
openai-python's "validate loosely, preserve everything": re-validation now
never raises, well-formed entries stay typed, and raw tool-call entries are
preserved as extras. Typed `choices`/`message` are unaffected.
Adds a mixed-precontext fixture + regression test.
Fixes#1
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

@Khurdhula-HarshavardhanKhurdhula-Harshavardhan left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Khurdhula-Harshavardhan
Khurdhula-Harshavardhan deleted the fix/precontext-strict-validation branch July 20, 2026 23:24
Abhinavexist added a commit that referenced this pull request Jul 21, 2026
…est-id, escape hatches
- #1 .stream() now yields OpenAI ChatCompletionStreamEvents (content.delta/done,
tool-call events) via ChatCompletionStreamState; <think>/<precontext> stripped from
content events; text_deltas() for plain tokens; create(stream=True) unchanged.
- #2 streamed usage + system_fingerprint captured on get_final_completion().
- #3 _request_id carried onto the returned completion.
- #6 parse()/with_raw_response/with_streaming_response exposed on the wrapper
(no more AttributeError; parse delegates to the OpenAI client, model default + guard).
Rebased onto main (post #7#11).
Abhinavexist added a commit that referenced this pull request Jul 22, 2026
…est-id, escape hatches
- #1 .stream() now yields OpenAI ChatCompletionStreamEvents (content.delta/done,
tool-call events) via ChatCompletionStreamState; <think>/<precontext> stripped from
content events; text_deltas() for plain tokens; create(stream=True) unchanged.
- #2 streamed usage + system_fingerprint captured on get_final_completion().
- #3 _request_id carried onto the returned completion.
- #6 parse()/with_raw_response/with_streaming_response exposed on the wrapper
(no more AttributeError; parse delegates to the OpenAI client, model default + guard).
Rebased onto main (post #7#11).
Abhinavexist added a commit that referenced this pull request Jul 22, 2026
…est-id, escape hatches (#20)
- #1 .stream() now yields OpenAI ChatCompletionStreamEvents (content.delta/done,
tool-call events) via ChatCompletionStreamState; <think>/<precontext> stripped from
content events; text_deltas() for plain tokens; create(stream=True) unchanged.
- #2 streamed usage + system_fingerprint captured on get_final_completion().
- #3 _request_id carried onto the returned completion.
- #6 parse()/with_raw_response/with_streaming_response exposed on the wrapper
(no more AttributeError; parse delegates to the OpenAI client, model default + guard).
Rebased onto main (post #7#11).
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

@Abhinavexist@Khurdhula-Harshavardhan