Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

constrain output to specfic language #1397

Open
Sayed-Ameer opened this issue Jan 30, 2025 · 1 comment
Open

constrain output to specfic language #1397

Sayed-Ameer opened this issue Jan 30, 2025 · 1 comment

Comments

@Sayed-Ameer
Copy link

When using BAML, is there a way to force the LLM to output exclusively in Arabic? Even with test cases in place, some words occasionally appear in other languages.
For context, other structured generation libraries like Outlines allow the use of character regex patterns to enforce language constraints. However, I prefer using BAML for its overall functionality.

@hellovai
Copy link
Contributor

on way to do to this is to leverage our functionality to modify the prompt more carefully.

For example:

class Resume {
  name string @alias("<arabic for name>")
  ...
}

function InArabic(foo: string) -> Resume {
  client MyClient
  prompt #"
    < instructions in arabic >
    {{ ctx.output_format(prefix="<arabic>")
    {{ _.role('user') }}
    {{ foo }}
  "#
}

See more ways to modify any part of the prompt we inject here: https://docs.boundaryml.com/ref/prompt-syntax/ctx-output-format

See more ways to rename fields in your datamodels: https://docs.boundaryml.com/ref/attributes/alias

That said, i would also like to just support constrained generation here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants