https://www.boundaryml.com logo
find myself re-inventing schema aligned
# suggestions
a
find myself re-inventing schema aligned parser for scenarios where dynamic types arent flexible enough (e.g. when returning bare primitive values w no object wrapper) - either direct parser access or being able to set dynamic return of function to primitive would solve this for me. preferably direct parser access tbh
v
can you share what code snippet you would love to see?
a
vaguely something like
Copy code
baml.sap(raw_response: string, schema: JsonSchema) -> obj
or typebuilder, supposing there is also a jsonschema->tb converter
v
could you share what you mean by:
Copy code
find myself re-inventing schema aligned parser for scenarios where dynamic types arent flexible enough
I'm guesing you're doing something like top level return type is
string
then writing a parser?
a
yup
v
and the reason you can't do this is because top level type should really be a generic T?
but you need to do string
and then it breaks?
a
its cus if i have
Copy code
class ExtractedData {
    @@dynamic
}

function ExtractData (prompt: string, data: string) -> ExtractedData {
  client GenericAIConnectorClient
  prompt #"
    {{ _.role("system") }}
    {{ prompt }}
    {{ ctx.output_format }}

    {{ _.role("user") }}
    <data>
    {{ data }}
    </data>
  "#
}
then ExtractedData can never just be directly string, number, etc
v
I see, and sometimes you want it to just be a bare type
a
yup, but also more generally would have use for direct parser access in variety of spots
v
well the parser problem coincidentally would get solved for free if we offered the top level dyn type
can then you could do:
Copy code
b.parse.ExtractData(...)
a
nice, that would be sick
v
yea i think really branded unions would solve this problem (and many more):
Copy code
union FooBar {
  @@dynamic
}

function ExtractData (prompt: string, data: string) -> FooBar {
  client GenericAIConnectorClient
  prompt #"
    {{ _.role("system") }}
    {{ prompt }}
    {{ ctx.output_format }}

    {{ _.role("user") }}
    <data>
    {{ data }}
    </data>
  "#
}
since that would work, where you could extend the FooBar union to have any type and it would behave like a single type
a
Yeah that makes sense
c
if we can programmatically construct any BAML type, does it mean we can implement a different syntax for BAML and potentially use it as some embedded DSL in another language ?
v
^yes