https://www.boundaryml.com logo
Prompt Optimization
# general
y
Hey guys. Just saw this and love it:

https://youtu.be/9b0yPIfDd08?si=saCHMPWDveuxdP9R▾

I had made my own lil poc to do something similar a few months ago: https://github.com/YourTechBud/ytb-practical-guide/blob/ft/dspy-baml/dspy-and-baml/main_advanced.py I honestly prefer Greg's way of optimizing the entire baml function to what I have done. Happy to share my feedback and learnings. Would love to contribute in any way possible to make this happen.
g
My Tech Bud! Very glad if you think the approach makes sense! I'd love all your feedback and suggestions, either here or on a call if you're free some time.
Nice POC, somehow I missed it. Do you think there are some advantages to using external Examples over BAML tests?
p
Off the top of my head (and @yourtechbud and I just spoke about this earlier this evening), on the surface, external examples are more or less equivalent to BAML tests. What I think is actually more of a stark difference is the feedback mechanism, which is crucial to the optimization process, but for which BAML tests are clunky
When we keep examples and scoring/feedback functions separate (as we do in DSPy), we can create much more elaborate scores and feedback strings that are very informative to the reflection LLM. It definitely influences the outcome of the optimization
The other thing about BAML tests that are clunky, and why the interface is not ideal for optimization, is the train/val/test split. There needs to be a held-out test set that isn't seen by the model during training, and GEPA also uses a validation set that it uses to evaluate results at intermediate stages of optimization
In DSPy, it's very much like data science - you create randomized, stratified, sampled train/val/test splits using external functions, and define elaborate scoring/feedback functions that are specific to the domain at hand
BAML tests seem quite limiting on that front
But I still think the bigger concern is that there doesn't seem to be a clear way to customize the feedback the LLM sees now with the test interface in BAML
Now that I think about it, even for scoring, BAML's tests aren't ideal. Not only is a binary pass/fail condition not a great scoring metric, it's arguable that even a simple scalar metric for a compound workflow that uses 2+ prompts may not be ideal. This is an interesting blog on how folks are defining custom scoring functions for GEPA https://www.elicited.blog/posts/non-obvious-things-about-gepa
So, in summary, BAML tests are limiting from several perspectives: - Feedback - Scoring - Train/val/test splits
g
Here's a more thorough doc https://github.com/BoundaryML/baml/tree/canary/beps/docs/proposals/BEP-005-prompt-optimization We have one thing for making the tests more flexible:
@@check( domain1, {{ predicate }} )
@@check( domain2, {{ predicate }} )
Using names for checks to group them together, and then giving those different domains different weights when you start the optimization. You could use this for train/test splits as well. For feedback and scoring, those are great points. Maybe we should add some syntax in BAML for that.
y
Hey @greg (BAML), heres some rough notes i had made. Happy to get on a call to discuss further. https://github.com/YourTechBud/ytb-practical-guide/blob/ft/dspy-baml/dspy-and-baml/BAML.md
I think @prrao covers this really well. Its not just about externalizing the examples though. I also prefer externalizing the metric function itself. Why external examples: - allows me to load them up from a database or Observability system. I really dont wanna see 100s of examples in my codebase. I'd rather have them stored in a parquet file in s3 Why external metric functions? - Prashanth covers this perfectly well. Each on of his point is something i resonate with as well - static matches arent enough. We often need complex metric functions with may use LLMs as judge and what not. - its easier to integrate with 3rd party evaluation systems when cause they have plugins in JS and Python.
Having said that. I only find the need to use an optimizer for a small subset of my prompts where the scope is very clear and well defined.
a
once we launch workflows (soon^TM), we will make asserts actually support simple expressions as well as calling other llm functions, which should cover some of this
p
Will the workflow release support strings as variables 😬
@greg (BAML) showed a function-based approach to allow strings as variables that could work, just hoping that comes out sometime soon
g
We'll have to discuss a bit exactly how to support sharing strings. I think it's possible to give you either top-level strings or pure functions that return a sharable string, and to use those to improve sharing in tests, before we do the release of the full language. Maybe it's a matter of making
template_string
work in test arguments. IMO this is something worth running by the team to see if we can solve on one of our Fridays.
p
Yeah if template strings could work with a few tweaks that could do it too
g
Nice 🙂 That's exactly what we're discussing right now on internal slack.
p
I presume the full language will be in beta testing for quite a while 😅
y
This should work for most usecases. I hope we support calling host functions from those tests as well
But loading training a d eval examples from parquet/database seems to be like a must have feature. Atleast for me