https://www.boundaryml.com logo
🟑 Associating FunctionLogs with Streamed Parsed D...
# questions
v
Is there a way to reliably associate FunctionLogs (from OnTick) with streamed parsed data? My use case is to stream the raw LLM response while simultaneously consuming the partial streamed data for visualization purposes Using the Go client if it matters
t
also interested πŸ™‚
b
This is an interesting one - you want to render both the raw response and parsed response simultaneously? Or is this a "we want to expose the reasoning alongside the streamed data" request?
v
I am not sure how "rendering the raw and parsed responses simultaneously" and "expose the reasoning alongside the streamed data" are any different, unless by "reasoning" you're implying the use of reasoning models, and if so, I'm not using any reasoning models at the moment. I am asking whether there is supposed to be any correlation between OnTick function logs and the stream values that come out of the channel. I saw that both appear to be the same length, with function logs being one less. I assume it's because
OnTick
does not get called with the very last function log as none of the logs had a request duration when I logged them, but I'm not sure whether this holds true for all cases (maybe even if we throw reasoning models into the mix; would I get the same amount of empty stream values as function logs while the model is outputting reasoning tokens?), so I suppose that's what my question is. My current use case is to stream both the parsed and raw responses side by side for an internal testing web app we're building at work, but I'm also just curious in general as to how
OnTick
is supposed to be used for anything meaningful besides debug logs. Looking at the documentation,
OnTick
seems to be the only source of live raw response information, yet there are no common identifiers between the stream values and function logs that would allow me to bundle them together and, e.g., send them as a pair to the frontend.
b
Got it - I wasn't sure exactly how to interpret your question, hence the request for clarification. We've been deliberate about keeping the
b.call
and
b.stream
interfaces as simple as possible, which is why they look the way they do right now. I would not treat the stream event count as 1:1 between the two - the fact that they do is an accidental implementation detail more than anything else.
OnTick
was originally meant to give people access to fields like
reasoning.summary
or just response output that we don't surface (e.g. if the model explains its output before returning a
'''json <code>'''
block), but this is one that we'll look into exposing!
t
i want to be able correlate them yes
ive been curious about getting spans of whats being parsed to remove it from the streamed value
v
Yeah, that makes sense. I was reluctant to assume the correlation between the two was intentional; if that were the case, this would be quite a bizarre API design for something that could've been a getter on the stream value. I suppose a simpler alternative that would work for me is if the streamRequest API, currently available for TypeScript and Python, were also available in Go. This way, I could control the streaming myself and know for sure which raw response correlates with which parsed value. As far as I can see, parsing is already available, so I hope it wouldn't be too hard to add the first half, considering it is already implemented in the core runtime. Does the above make sense? If so, is it already planned for a near-future release? This issue is currently a significant blocker for us.
b
cc @Vaibhav (BAML πŸ‘) - how hard would this be?
v
We can make it happen! It should in theory be quite easy
v
Hey! Any updates on this?
i
@Vaibhav (BAML πŸ‘) is progress on this matter tracked anywhere? also interested
v
hey folks! we had a few requests come in for this, but not enough so we had deprioritized this! There is however an easy workaround. You can just use
onTick
combined with a
b.parse_stream.YourFunction(..)
and that should "just work". you don't even need
b.stream
with this approach!
Copy code
python
def on_tick(result: FunctionLog):
   # get raw_string by accessing text
   raw = result.<depends on api>
   
   # note, parsing may fail so events may need to be dropped.
   parsed_result = b.parse_stream.MyFunction(raw)

result = b.MyFunction(..., baml_options={ "on_tick": on_tick })
the issue with syncing stuff is just we need to create a new
id
for what version of the function log you had. we can also consider putting the streamed object into the function log itself but we don't do that due to memory
t
Imma push back some here @Vaibhav (BAML πŸ‘)
Who is using ontick and doesn’t want this?
I challenge you to find that customer
I don’t see how they could exist. The way ontick works if you are displaying that to users (my guess the main reason to use it) you don’t want a random json blob at the end
v
hmm, so i guess ideally you want something like this:
Copy code
def on_tick(result: FunctionLog, streamed_result: Option[T]):
   # get raw_string by accessing text
   raw = result.<depends on api>
i
What's with the
<depends on api>
part? Rather, what's with the
raw_llm_response
field on the
FunctionLog
class if it is unusable in this context? https://cdn.discordapp.com/attachments/1415441570689318963/1438272712186527774/Home_2025-11-12_at_11.01.46_PM.png?ex=69164758&is=6914f5d8&hm=3ebfe02c14971da13393231eac94691f53386914b03ff9bb267bce26449a3af0&
I was hoping I could get some workaround going by using the streaming API + ontick so I can look at the
sse_chunks
available on `LLMStreamCall`s as the
text
property on each chunk made it seem like it would contain the actual delta of said SSE chunk, but I was disappointed to find out it is just the unparsed chunk... It seems like a trend for the collector/ontick APIs to put the burden of knowing how to deal with each individual LLM provider on the user, which seems ridiculous, considering BAML clearly knows how to do so already. Sure, this is simple enough if one were to use OpenAI for everything, or if one were to just hardcode the expected structure for each prompt based on the provider used, but what if I have a fallback configured that possibly falls back to a completely different provider? I have to agree with tbermann here, the collector API only really seems useful for metrics collection in practice, and doesn't appear to match the advertised capabilities all that well
v
oh you can use the
raw_llm_response
field as well!
but it doesn't work too well for streaming
the issue with thinking tokens is that we don't actually extract them out for every field. What i think we should do is something similar to what we do for cost actually. we built a projection that allows us to configure how to calculate cost for every model via a simple config as a function of each model. i think we can do something similar here for
raw_response_text
or
thinking
etc and just expose the function to be a UDF
(udf => user defined function)
let me think on this and see how we can do this nicely so we can project any field to a "known" standard that you can define as a developer.
t
i mean, they arent 'thinking' tokens in any meaningful measure
all the models i am using send back a response
that response includes some chain of thought output, some random stuff and then a structured json blob that baml is parsing
one of the main values (to me) for baml is its ability to do a very very good job parsing that json response
but that doesn't mean the rest of the response is uninteresting. quite the opposite!
I think the feature being asked for isn't 'expose thinking tokens' its really 'give me the llm response in a sane streaming fashion that understands that i expect to get back a combination of structured and unstructured data'