mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-09 03:18:44 +00:00
fix(guardrails): narrow the stream delta before writing to it
basedpyright could not prove the delta was non-None on the write path, and reportOptionalMemberAccess has a zero budget. The guard is also clearer than relying on the text check to imply it.
This commit is contained in:
parent
b6e3e6decd
commit
295ad527d5
1 changed files with 3 additions and 3 deletions
|
|
@ -381,12 +381,12 @@ class LLMShieldGuardrail(CustomGuardrail):
|
|||
text = getattr(delta, "content", None) if delta is not None else None
|
||||
is_final = self._is_final_chunk(chunk)
|
||||
|
||||
if not isinstance(text, str) or not text:
|
||||
if delta is None or not isinstance(text, str) or not text:
|
||||
# Nothing to restore in this chunk, but a final chunk still has to
|
||||
# flush whatever the window is holding.
|
||||
if is_final and carry:
|
||||
if is_final and carry and delta is not None:
|
||||
emitted, carry = await self._stream_step("", carry, True, session_id)
|
||||
if emitted and delta is not None:
|
||||
if emitted:
|
||||
delta.content = emitted
|
||||
yield chunk
|
||||
continue
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue