litellm/tests/unit/llms/openai/chat
mika-lt 3e086e25c9
fix(hosted_vllm): keep vLLM's prompt_token_ids on the first streamed chat chunk (#51087)
* fix(hosted_vllm): keep vLLM's prompt_token_ids on the first streamed chat chunk

vLLM sends prompt_token_ids and prompt_text at the top level of the first
stream chunk, but the OpenAI stream parser rebuilt each chunk from a fixed
key list and the proxy's fast serializer skipped unknown top-level fields,
so streamed calls lost them while non-streamed calls kept them.

The OpenAI stream parser now takes the top-level fields to keep as a
constructor argument, which hosted_vllm sets to vLLM's two prompt fields,
and the proxy sends a chunk carrying one through the regular serializer.

* fix(hosted_vllm): keep vLLM prompt fields through the rebuilt stream, cache replay, and redaction

Skip null prompt fields on the chunk, keep the first streamed value in stream_chunk_builder, replay cached prompt fields on the first frame, and drop both fields under turn_off_message_logging

* fix(hosted_vllm): keep vLLM prompt fields out of Presidio logging-only logs and redact prompt_logprobs

Presidio's logging-only hook now hands loggers copies of the response, the logging payload, and the rebuilt stream without vLLM's prompt_token_ids, prompt_text, and prompt_logprobs, since token ids cannot be masked. The client's response keeps them

Message-logging redaction also drops prompt_logprobs, whose decoded tokens spell out the prompt

* fix(logging): keep vLLM prompt fields out of logging-only guardrail logs and on guardrail-rebuilt streams

A logging-only guardrail's hook output now goes to loggers without vLLM's prompt fields, an opted-out logger gets the redaction placeholder for stream chunks, a stream rebuilt from a full response keeps the prompt fields, and the cache key covers return_prompt_text

* fix(logging): keep vLLM prompt fields in logs unless a logging-only guardrail masked them, and on incremental_diff guardrail streams

* fix(logging): still run logging-only guardrails when the logged content cannot be fingerprinted

A message too deep for pydantic_core to serialize made the fingerprint raise, so the
logging loop skipped the guardrail and logged the unmasked messages. The fingerprint is
now best effort, and without one the vLLM prompt fields are dropped from the logs

* fix(logging): drop vLLM prompt fields from every later log once a logging-only guardrail masked a stream chunk

* fix(logging): drop vLLM prompt fields from each logged text completion choice and skip the logging-only change check unless the request asked for them

turn_off_message_logging and a masking logging-only guardrail now also drop the
prompt_token_ids and prompt_logprobs vLLM puts on each /v1/completions choice.
The logging-only guardrail change check only serializes the logged content when
the request set return_token_ids, return_prompt_text, or prompt_logprobs

* fix(guardrails): put vLLM prompt fields only on the first released chunk when tool calls are held

With streaming_hold_tool_calls and incremental_diff, each held tool-call fragment got the prompt fields
because nothing had been sent yet when it was held. The fields are now added when the chunk is released,
so only the first chunk the client receives carries them

---------

Co-authored-by: mateo-berri <277851410+mateo-berri@users.noreply.github.com>
2026-11-25 19:54:45 -08:00
..
guardrail_translation fix(guardrails)!: close gaps in bedrock tool call and tool description scans (#54169) 2026-11-25 06:56:15 +00:00
__init__.py test(unit): make every tests/unit directory a package so pytest collection is unique 2026-09-20 11:50:59 +00:00
test_openai_gpt_transformation.py fix(hosted_vllm): keep vLLM's prompt_token_ids on the first streamed chat chunk (#51087) 2026-11-25 19:54:45 -08:00