https://www.boundaryml.com logo
🟡 BAML JSON Parser Usage Without Prompts
# questions
t
Is there a way to use BAML's JSON parser without the BAML prompts? We switched from BAML to Langfuse for prompt management and o11y so non-developers could own part of the feature development to move faster -- but the downside we're seeing is parsing JSON responses is a real PITA. BAML shined here -- a lot because of the prompts themselves (type definitions re: https://boundaryml.com/blog/type-definition-prompting-baml) and the wrapping framework... But I can't seem to find reference of just how BAML parses the schema so well. We'd love to add that back and get the best of both worlds (at least until the Boundary studio is more feature rich!) It looks like there's some references to JSONish, but that was never finished or wasn't it.
v
(Out in some calls) but I’ll reply more thoroughly in about 1 hour. TLDR look up modular API. But we’ve seen more success with a few other ways for nontechnical folks using us. I’ll share those when I’m back!
t
Hmm, looks like you're just relying on serde_json from_str unwrap mainly and then do some additional type logic on top of that
b
llm-response-parser is not the right place to look, that’s not in the critical path in the runtime
t
sure -- saw this wrapper:
Copy code
// Send the HTTP request.
  const res = await fetch(req.url, {
    method: req.method,
    headers: req.headers,
    body: JSON.stringify(req.body.json())
  })
  // Parse the HTTP body.
  const body = await res.json() as any
  // Parse the LLM response.
  const parsed = b.parse.ExtractResume(body.choices[0].message.content)
JSON.stringify is failing us in a small percentage of use cases
(nbsps instead of spaces) among other idiosyncrasies
b
Was that an issue that BAML was solving for you before? I don’t think we do any url encoding magic on inputs…
t
we've handled it through a lot of custom logic -- but I thought you might've already solved it so it's code we don't have to maintain 🙂
No, in the LLM responses for the JSON body formatting we're getting nbsps, newlines, and all sorts of other crap
b
Oh- yeah, that’s what b.parse is meant for.
t
(bad example, sorry)
I don't see any docs on b.parse in the modular api
so I think the problem with that is it requires the BAML model and function
b
I hear what you're saying! It's a tricky problem, and there's actually a few reasons we don't really expose the API I think you're imagining (one of them being the potential for version skew between the schema you describe in a prompt and the schema used by your parser) - unfortunately I have to run to another call, but when Vaibhav frees up he can explain this more in depth
t
I think I'm looking at
parse_llm_response
but am just unfamiliar with rust 🙂 so not sure
(would still love to hear your approach to taking on langfuse pm-friendliness -- but no rush !)
a
oh we would 100% want to implement a UI for non-devs to modify prompts on teh fly!
we would love love love to get your feedback once we have something working
(even if youre still on langfuse)