BoundaryML/baml · error · Exception
BAML Internal error: Stream did not complete successfully…
Error message
BAML Internal error: Stream did not complete successfully. Please report this issue.
What it means
baml_py.stream.get_final_response() raises this generic Exception when a streamed BAML call ends without an exception but also without a result, meaning the stream's internal state machine finished in a neither-success-nor-failure state. The library considers this impossible under normal operation and asks for a bug report.
Solutions
- Check server/network conditions: retry the request, since a dropped stream can leave no result and no exception.
- Guard with streaming callbacks to ensure the stream is fully consumed before calling get_final_response().
- Upgrade baml-py and the BAML CLI to the latest versions — this state may be a fixed engine bug.
- If reproducible on latest versions, report it (the message explicitly asks for a bug report) with a minimal repro.
Example fix
# before
stream = b.MyFunc.stream(prompt)
result = stream.get_final_response() # may hit internal error on abrupt stream end
# after
stream = b.MyFunc.stream(prompt)
for partial in stream:
pass # fully consume the stream
try:
result = stream.get_final_response()
except Exception as e:
result = fallback_completion(prompt) Defensive patterns
Strategy: try-catch
Validate before calling
if not stream.has_pending_items() and stream.get_final_response_cache() is None:
# stream never produced output; re-issue instead of forcing final response
stream = client.call.stream(...) Type guard
def stream_completed(stream) -> bool:
try:
stream.get_final_response()
return True
except Exception:
return False Try / catch
try:
result = stream.get_final_response()
except Exception as e:
if "Stream did not complete successfully" in str(e):
result = retry_stream(client, prompt) # re-issue the request
else:
raise Prevention
- Fully consume the stream before calling get_final_response()
- Avoid cancelling the event loop / process mid-stream
- Retry transiently failed streams rather than forcing a final response
- Keep baml-py and the engine up to date; report reproducible cases
When it happens
Trigger: Calling stream.get_final_response() after joining the streaming task when self.__result is None and self.__exception is None — e.g. the async streaming task ended without invoking either the result or error callback.
Common situations: Killed or cancelled stream tasks mid-flight (process interrupts, event-loop shutdown) that bypass both callbacks; engine/FFI bugs in rare partial-response paths; forcing final response on a stream that never started consuming.
Understand the failure class
Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.
Related errors
AI-assisted analysis of BoundaryML/baml@bd85ce9dee (2026-09-12).
Data as JSON: /api/errors/92153caf814a6241.
Report an issue: GitHub.
Appendix: source
Thrown at engine/language_client_python/python_src/baml_py/stream.py:221
if done_seen:
break
except Exception as e:
raise e
finally:
if self.__task and self.__task.is_alive():
self.__task.join(timeout=5.0)
def get_final_response(self):
self.__drive_to_completion_in_bg()
if self.__task is not None:
self.__task.join()
if self.__exception is not None:
raise self.__exception
if self.__result is None:
raise Exception(
"BAML Internal error: Stream did not complete successfully. Please report this issue."
)
return self.__final_coerce(self.__result)
View on GitHub (pinned to bd85ce9dee)