-
Notifications
You must be signed in to change notification settings - Fork 279
[doc] update baml example instruction on user roles #1316
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
Merged
+16
−0
Merged
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
338046d
Update 03_postgres_source.md
badmonster0 da109ea
fix link
badmonster0 42b4ad4
Merge branch 'main' into doc-fix
badmonster0 e119cdf
Merge branch 'main' into doc-fix
badmonster0 97ddfff
new example
badmonster0 ec6ce9d
move tutorial to top bar
badmonster0 e9120ce
Merge branch 'main' into doc-fix
badmonster0 556a93d
more tutorial
badmonster0 803251f
Merge branch 'main' into doc-fix
badmonster0 2bf5d91
Update document_ai.md
badmonster0 bada3ef
Merge branch 'main' into doc-fix
badmonster0 89333ca
[example] bump baml version
badmonster0 23b99d7
Merge branch 'main' into doc-fix
badmonster0 54cd9fc
[doc] images
badmonster0 14f98b2
Merge branch 'main' into doc-fix
badmonster0 14d3555
[doc] clip example
badmonster0 9bdf64a
Merge branch 'main' into doc-fix
badmonster0 106b397
Delete example (73).png
badmonster0 3f93323
docs category
badmonster0 fff327d
Merge branch 'main' into doc-fix
badmonster0 dfed73f
[doc] baml
badmonster0 9b95653
Merge branch 'main' into doc-fix
badmonster0 8a894c7
image resize
badmonster0 4fa58ff
Merge branch 'main' into doc-fix
badmonster0 75876e6
Update patient_form_extraction_baml.md
badmonster0 d851e60
Merge branch 'main' into doc-fix
badmonster0 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -142,6 +142,7 @@ function ExtractPatientInfo(intake_form: pdf) -> Patient { | |
| Extract all patient information from the following intake form document. | ||
| Please be thorough and extract all available information accurately. | ||
|
|
||
| {{ _.role("user") }} | ||
| {{ intake_form }} | ||
|
|
||
| Fill in with "N/A" for required fields if the information is not available. | ||
|
|
@@ -153,6 +154,21 @@ function ExtractPatientInfo(intake_form: pdf) -> Patient { | |
|
|
||
| We specify `client Gemini` and a prompt template. The special variable `{{ intake_form }}` injects the PDF, and `{{ ctx.output_format }}` tells BAML to expect the structured format defined by the return type. The prompt explicitly asks Gemini to extract all fields, filling “N/A” if missing. | ||
|
|
||
| :::tip Why `role("user")` Matters in BAML Extraction | ||
|
|
||
| In our BAML example above, there's a subtle but **crucial line**: `{{ _.role("user") }}` is added at the start of the prompt. | ||
|
|
||
| > This ensures the **PDF content is explicitly included as part of the user message**, rather than the system prompt. | ||
|
|
||
| **Why does this matter?** | ||
| - For Gemini and Anthropic models, BAML can sometimes infer or adjust the prompt structure, so extraction works either way. | ||
| - For **OpenAI models** (e.g., GPT-4/GPT-4o), if the PDF is **not** in the user role, the model doesn't see the file content — so extractions will fail or return empty fields. | ||
| - This can easily trip you up.If you're using BAML, **always double-check your prompt roles when adding file inputs**—especially for OpenAI backends. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: missed a whitespace |
||
|
|
||
| ::: | ||
|
|
||
|
|
||
|
|
||
| ## Configure the LLM client to use Google’s Gemini model | ||
|
|
||
| ```python | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"BAML can sometimes infer or adjust the prompt structure"
Is it how it works? (I'm not sure, may missed something if this is specified somewhere)
I think it's just some subtle request format difference between OpenAI and others, so others tolerate that in the system prompt, while OpenAI doesn't.