rjurney
09/13/2025, 9:14 PMAntonio Sarosi (BAML π)
09/13/2025, 11:12 PMctx.output_format but even for that you have [some control](https://docs.boundaryml.com/ref/prompt-syntax/ctx-output-format)rjurney
09/14/2025, 2:27 PMrjurney
09/14/2025, 2:28 PMAntonio Sarosi (BAML π)
09/14/2025, 5:12 PMtypescript
enum Category {
Positive
Negative
}
function Categorize(comment: string) -> Category {
client GPT5
prompt #"
Given these examples:
The product is great!: Positive
I don't like this product: Negative
categorize the following comment. {{ ctx.output_format }}
{{ comment }}
"#rjurney
09/14/2025, 5:27 PMAntonio Sarosi (BAML π)
09/14/2025, 5:54 PMAntonio Sarosi (BAML π)
09/14/2025, 5:54 PM{{ variable }} formats it as JSONrjurney
09/14/2025, 6:31 PMrjurney
09/15/2025, 2:38 AMtypescript
class CompanyList {
block_key string? @description("The blocking key used to merge records.")
block_key_type string? @description("The blocking strategy this block key comes from.")
block_size int? @description("The number of records merged by entity resolution.")
companies Company[]
}
class MergedCompany {
id int? @description("Unique among all objects. Add to source_ids when merging.")
source_ids int[]? @description("List of source Company.ids that were merged to create this Company.")
}
class FewShotMergedCompanies {
companies MergedCompany[]
}
function MultiEntityResolution(company_list: CompanyList, few_shot_examples: FewShotMergedCompanies) -> CompanyList {
// see clients.baml
client Gemini20Flash
// The prompt uses Jinja syntax. Change the models or this text and watch the prompt preview change!
prompt #"
Examine the following set of companies and determine... <lots of instructions>...
...
Given these examples:
{{ few_shot_examples }}
Return a merged set of companies with all combined attributes from the source companies filled out.
{# special macro to print the output instructions. #}
{{ ctx.output_format(hoist_classes=["Company", "Ticker", "CompanyList"]) }}
{{ _.role("user") }}
Company List: {{ company_list }}
}rjurney
09/15/2025, 2:40 AMVaibhav (BAML π)
09/15/2025, 2:42 AMrjurney
09/15/2025, 3:23 AMpython
class MergeCompany {
id int? @description("Unique among all objects. Add to source_ids when merging.")
source_ids int[]? @description("List of source Company.ids that were merged to create this Company.")
}
class FewShotExample {
company MergeCompany
merged_company MergeCompany
}
class FewShotMergedCompanies {
merge_companies FewShotExample[]
}rjurney
09/15/2025, 3:23 AMrjurney
09/15/2025, 3:23 AMFewShotExample classes outside a class? How?Vaibhav (BAML π)
09/15/2025, 3:24 AMFewShotExample[] directly as well if thats what you meantrjurney
09/15/2025, 3:26 AMrjurney
09/15/2025, 3:26 AMVaibhav (BAML π)
09/15/2025, 3:27 AMrjurney
09/15/2025, 3:29 AM...
prompt #"
Important stuff...
Given these examples:
{{ few_shot_company_merges }}
...
Return a merged set of companies with all combined attributes from the source companies filled out.
{# special macro to print the output instructions. #}
{{ ctx.output_format(hoist_classes=["Company", "Ticker", "CompanyList"]) }}
{{ _.role("user") }}
Company List: {{ company_list }}
"#
I just want to get data in {{ few_shot_company_merges }} that is a subset of my big fat Company class with just two fields: id and source_ids, an integer and a list of integers.
Here is my 2-field company class, MergeCompany in BAML land:
class MergeCompany {
id int? @description("Unique among all objects...")
source_ids int[]? @description("List of foo...")
}
I need to get a list of those in JSON... in whatever format will make my prompt the most accurate.Vaibhav (BAML π)
09/15/2025, 3:30 AMVaibhav (BAML π)
09/15/2025, 3:30 AMrjurney
09/15/2025, 3:30 AMVaibhav (BAML π)
09/15/2025, 3:30 AMVaibhav (BAML π)
09/15/2025, 3:30 AMrjurney
09/15/2025, 3:31 AMrjurney
09/15/2025, 3:31 AMmerge_companies: MergeCompany[]
But you guys know the best format, not me. That is your entire focus.rjurney
09/15/2025, 3:32 AMrjurney
09/15/2025, 3:32 AMrjurney
09/15/2025, 3:32 AMVaibhav (BAML π)
09/15/2025, 3:33 AMrjurney
09/15/2025, 3:34 AMrjurney
09/15/2025, 3:34 AMtypescript
class CompanyList {
@@description("Retain all Company.id values in source_ids when merging.")
block_key string? @description("The blocking key used to merge records.")
block_key_type string? @description("The blocking strategy this block key comes from.")
block_size int? @description("The number of records merged by entity resolution.")
companies Company[]
}
class MergeCompany {
@@description("A simple Company object to track merges of Company records.")
id int? @description("Unique among all objects. Add to source_ids when merging.")
source_ids int[]? @description("List of source Company.ids that were merged to create this Company.")
}
class FewShotExample {
companies MergeCompany[] @description("Input companies to be merged.")
merged_company MergeCompany @description("The resulting merged company, with all the input companies' Company.id values in source_ids.")
}
class MergeCompanyExamples {
@@description("A collection of few-shot examples for merging companies.")
merge_companies FewShotExample[]
}
function FewShotMultiEntityResolution(company_list: CompanyList, few_shot_company_merges: MergeCompanyExamples) -> CompanyList {
// see clients.baml
client Gemini20Flash
prompt #"
Given these examples of merging companies:
{{ few_shot_company_merges }}
Examine the following set of companies and determine which ones are the same entity...
...
Return a merged set of companies with all combined attributes from the source companies filled out.
{# special macro to print the output instructions. #}
{{ ctx.output_format(hoist_classes=["Company", "Ticker", "CompanyList"]) }}
{{ _.role("user") }}
Company List: {{ company_list }}
"#
}rjurney
09/15/2025, 3:40 AMrjurney
09/15/2025, 3:44 AMrjurney
09/15/2025, 3:44 AMrjurney
09/15/2025, 3:47 AMrjurney
09/15/2025, 4:00 AMid fields in source_ids field? I lose 30% of them with blocks of 30 at the moment. I need 100%.Vaibhav (BAML π)
09/15/2025, 4:04 AMtemplate_string FewShotCompanies(example: MergeCompanyExamples) #"
For example:
{% for c in example.companies %}
{{ c }}
{% endfor %}
Would merge into:
{{ example.merged_company }}
"#Vaibhav (BAML π)
09/15/2025, 4:04 AM{{ FewShotCompanies(few_shot_company_merges) }}Vaibhav (BAML π)
09/15/2025, 4:04 AMVaibhav (BAML π)
09/15/2025, 4:04 AMrjurney
09/15/2025, 4:05 AMrjurney
09/15/2025, 7:32 AMpython
def company_dicts_to_baml(
merge_company_example_set_dict: dict[
str, # merge_companies
list[ # MergeCompanyExampleSet.merge_companies
dict[
str, # companies / merged_company
Union[
list[dict[str, Union[int, list[int]]]], # MergeCompany
dict[str, Union[int, list[int]]], # MergeCompany
], # This is also to format the line I hope
] # This is also to format the line I hope
], # This is to format the line I hope
],
) -> MergeCompanyExampleSet:rjurney
09/15/2025, 7:32 AMrjurney
09/15/2025, 7:50 AM2025-09-15 00:49:14,382 - abzu.spark.er_eval - INFO - ENTITY RESOLUTION EVALUATION SUMMARY - ITERATION 1
2025-09-15 00:49:14,382 - abzu.spark.er_eval - INFO - ============================================================
2025-09-15 00:49:14,382 - abzu.spark.er_eval - INFO - Original raw companies (iteration 0): 13,641 total, 13,641 unique
2025-09-15 00:49:14,382 - abzu.spark.er_eval - INFO - Current iteration (1) resolved: 4,731 total, 4,718 unique
2025-09-15 00:49:14,383 - abzu.spark.er_eval - INFO -
2025-09-15 00:49:14,383 - abzu.spark.er_eval - INFO - DATA REDUCTION:
2025-09-15 00:49:14,383 - abzu.spark.er_eval - INFO - From original: 8,923 companies (65.41%)
2025-09-15 00:49:14,383 - abzu.spark.er_eval - INFO -
2025-09-15 00:49:14,383 - abzu.spark.er_eval - INFO - UUID VERIFICATION (should all be 0%):
2025-09-15 00:49:14,383 - abzu.spark.er_eval - INFO - Overlap with original: 74 UUIDs (0.54%)
2025-09-15 00:49:14,383 - abzu.spark.er_eval - INFO -
2025-09-15 00:49:14,383 - abzu.spark.er_eval - INFO - SOURCE UUID COVERAGE:
2025-09-15 00:49:14,383 - abzu.spark.er_eval - INFO - Original companies tracked: 11,855/13,641 (86.91%)
2025-09-15 00:49:14,383 - abzu.spark.er_eval - INFO - Total unique source_uuids: 11,855
2025-09-15 00:49:14,383 - abzu.spark.er_eval - INFO -
2025-09-15 00:49:14,383 - abzu.spark.er_eval - INFO - SOURCE UUID VALIDATION:
2025-09-15 00:49:14,383 - abzu.spark.er_eval - INFO - Valid references: 15,521/15,521 (100.00%)
2025-09-15 00:49:14,383 - abzu.spark.er_eval - INFO - Invalid references: 0/15,521 (0.00%)
2025-09-15 00:49:14,383 - abzu.spark.er_eval - INFO - ============================================================rjurney
09/15/2025, 7:52 AMrjurney
09/15/2025, 7:52 AMprrao
09/15/2025, 10:28 AMprrao
09/15/2025, 10:28 AMprrao
09/15/2025, 10:28 AMVaibhav (BAML π)
09/15/2025, 12:22 PMrjurney
09/15/2025, 5:59 PMrjurney
09/15/2025, 6:00 PMprrao
09/15/2025, 6:16 PM2025-09-15 00:49:14,383 - abzu.spark.er_eval - INFO - SOURCE UUID VALIDATION:
2025-09-15 00:49:14,383 - abzu.spark.er_eval - INFO - Valid references: 15,521/15,521 (100.00%)
2025-09-15 00:49:14,383 - abzu.spark.er_eval - INFO - Invalid references: 0/15,521 (0.00%)
What does this mean? 100%?prrao
09/15/2025, 6:16 PMprrao
09/15/2025, 6:16 PMprrao
09/15/2025, 6:17 PMprrao
09/15/2025, 6:17 PMrjurney
09/15/2025, 9:54 PMrjurney
09/15/2025, 9:56 PMrjurney
09/15/2025, 10:02 PMsql
+----------+----------+
|block_key |block_size|
+----------+----------+
|NVIDIA |869 |
|GOOGLE |310 |
|INTEL |275 |
|MICROSOFT |252 |
|AMD |220 |
|META |192 |
|AMAZON |183 |
|OPENAI |163 |
|TSMC |139 |
|APPLE |136 |
|SAMSUNG |119 |
|OKLO |93 |
|AWS |84 |
|BROADCOM |82 |
|TESLA |80 |
|CLOUDFLARE|69 |
|MP |67 |
|SK |65 |
|QUALCOMM |64 |
|ORACLE |63 |
+----------+----------+
Check out the largest blocks for iteration 2, based on the merges on the round 1 blocks π This is why I know it really fucking works. It is obvious major merging of the top companies occured. In the second round they will all get resolved.
sql
+---------+----------+
|block_key|block_size|
+---------+----------+
|THE |46 |
|GOOGLE |40 |
|US |37 |
|NVIDIA |34 |
|AMAZON |30 |
|SAMSUNG |27 |
|UC |26 |
|SK |26 |
|ST |24 |
|DC |22 |
|TM |22 |
|MICROSOFT|19 |
|AR |19 |
|PI |18 |
|LG |18 |
|PT |17 |
|INTEL |16 |
|SI |16 |
|KT |15 |
|AMD |15 |
+---------+----------+