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:
Ninad Phalak 2026-09-03 19:13:31 -05:00
parent b6e3e6decd
commit 295ad527d5
No known key found for this signature in database
GPG key ID: 59119ED515433744

View file

@ -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