https://www.boundaryml.com logo
🟑 Field Descriptions in Pydantic Classes Exported...
# questions
r
I see that the field descriptions aren't stored in my Pydantic classes that
baml-cli generate
exports - where are they stored?
p
I don't think they're stored. It's only accessible within the prompt that BAML generates at runtime. The client code only stored the basic Pydantic models without the field descriptions.
r
@prrao what were you saying about an alternative to Enum? I have every Bloomberg Stock Exchange Code, 2-letter codes that the LLM won't be able to map without a description... so what do I do in DSPy?
p
In BAML enums allow descriptions. You can add description annotations and use those. DSPy uses Python enums which are an inferior version of BAML's enums, so we can chat more about that later via DM πŸ˜…
Is doing this via enums the best way though? It requires a really expensive model with a huge context window to be able to take it all in and actually pick the right one
r
I’m not sure if it’s the best way, but yeah I use a big Enum with descriptions to go from the common exchange name to the Bloomberg code:
Copy code
typescript

enum Exchange {
  UN @description("NYSE - New York Stock Exchange")
  UQ @description("NASDAQ - NASDAQ Stock Market")
  UA @description("AMEX - American Stock Exchange")
  UR @description("ARCA - NYSE Arca")
  UM @description("NYSE American")
And yeah.thats the problem I immediately ran into in DSPy, but I’m sticking with BAML for the moment as I can definitely make things work with a combination of manual context engineering and some automated searches for the best few shot setup, a grid search basically πŸ™‚
Before I did this I had exceptions about unknown exchanges failing validation. This fixed them.
p
Yeah, description on enums is a really cool thing in BAML. In DSPy it's limited by Python's limited expressivity in enums (which are absolute garbage in Python) and you're limited to using string Literals, which don't have descriptions.
I think it could be possible to inject a string representation of the formatted enum as BAML does in DSPy, too. But that's one more function you'd have to maintain.. BAML's approach here is definitely the superior option πŸ‘
r
Copy code
enum Exchange {
  UN @description("NYSE - New York Stock Exchange")
  UQ @description("NASDAQ - NASDAQ Stock Market")
  UA @description("AMEX - American Stock Exchange")
  UR @description("ARCA - NYSE Arca")
I would need to provide an index like
{"UN": "NYSE - New York Stock Exchange"}
to the
BAMLAdapter
- can you control what data it receives?