https://www.boundaryml.com logo
🟑 Looking for a Python library to render prompts ...
# questions
m
Hi, is there any alternative to https://github.com/hhclaw/baml-lib for rendering prompts and validating outputs from python? Without LLM use etc.
b
We expose a modular API!
m
Thanks seems like exactly what I was looking for. Not sure how I (and Gemini) missed that completely!
b
We should do a better job of documenting it, for sure
That would probably help users and tools discover it more effectively πŸ™‚
m
Had a look at it - was able to get prompt rendering and parsing working. Is it possible to render a baml class as well? My use case is generating expected outputs for LLM fine tuning.
m
If I am not mistaken that gives the general output schema but I am looking for a way to take a specific instance of a baml class and render it to a string such that It would correctly be parsed back using b.parse. Basically a baml equivalent of json.dumps for baml classes / Pydantic objects
b
We don’t make it straightforward right now, but it’s possible!
Copy code
class Generic {
  foo TypeFoo
  bar TypeBar
}

function … -> Generic {
  prompt #”
      {{ ctx.output_format(hoist_classes=true) }}
  β€œ#
and then post-process in the modular api
m
That would still just give me schemas right? Not filled with specific data?
Looking for this functionality
Copy code
from baml_client.types import Resume

# 1. I have this Python Object (Instance)
my_resume = Resume(
    name="Alice",
    skills=["Python", "BAML"]
)

# 2. I want this String (Serialization)
# (Desired function: b.dumps(my_resume))
desired_output = """
{
  name: 'Alice',
  skills: ['Python', 'BAML']
}
"""
b
Oh, in that case
{{ resume }}
in the prompt template will do that
I thought you were talking about the classes themselves, not instances thereof πŸ™‚
m
That seems to just render it as standard json unfortunately.
Ended up using this function that basically mimicks the output format, worked for my specific model (was able to be parsed back). Would be quite nice to have this functionality natively though https://cdn.discordapp.com/attachments/1446952016906813461/1447217043790233730/message.txt?ex=69377a27&is=693628a7&hm=ad02b2155dbbb07c2e540cfb7032ef56745467cfe262fed352753e7c69986a09&
b
Ahh, now I understand what you were asking for
We'll look into it! We do support json/yaml/toon today, but we should also absolutely add TS value syntax to it: https://docs.boundaryml.com/examples/prompt-engineering/token-optimization#available-format-options
m
Yeah would be great to add that option and also make it available directly via a python function for dumping models rather than going through a baml function.