https://www.boundaryml.com logo
Hey! can you import functions/classes/
# general
v
Hey! can you import functions/classes/template_strings into other baml file?
g
They are imported automatically! Every file under baml_src sees the contents of every other file. You can not yet import across baml_src dirs.
v
i see, im defined a template_string that takes some params as input. im trying to use it in other functions as my standard prompt (in different files) but getting syntax issues. is there a correct way to do this?
g
Gochya. Can you share your code?
Putting the template string in its own file should be fine
You can test that by moving the template string into the same file that uses it (id expect the same error)
v
Copy code
// Template string for structured output extraction from medical documents
// Based on: https://docs.boundaryml.com/ref/baml/template-string

template_string StructuredOutputExtractionPrompt(
  document_content: string
) #"
You are a medical data extraction specialist. Your task is to extract structured information from medical documents and format it according to a precise JSON schema.

## Guidelines
- Extract ONLY information that is explicitly present in the document
- If a field is not found, omit it (unless it's required by the schema)
- Pay careful attention to units, values, and data types
- Preserve exact numerical values and dates as they appear
- Do not infer or make up information
- If a value is unclear or ambiguous, omit it rather than guessing

## Document Content
{{ document_content }}

---

## Task
Extract information from the document content above and return it in the exact JSON format specified by the schema. Return ONLY valid JSON matching the schema, with no additional text or commentary.

{{ ctx.output_format }}
"#
I want to use that ^ template in many files like so
Copy code
// Extract SUPAR data from medical document text
function ExtractSuPAR(document_text: string) -> SUPARData {
  client OpenAIReponsesApiGPT5
  prompt #"
    You are a medical data extraction specialist. Extract SUPAR (Soluble Urokinase Plasminogen Activator Receptor) test results from the following medical document.

    Extract metrics, values, units, and reference ranges. Common metrics include:
    - SuPAR Score (ng/ml)
    - Rate of Aging (unitless)
    - Biological Age (years)

    Extract ONLY information that is explicitly present in the document.
    If no SUPAR data is found, return an empty list.

    ## Document Content
    {{ document_text }}

    {{ ctx.output_format }}
  "#
}
g
Ahh, thanks!
ctx.output_format can only be used in functions
Then, if you want to use the template string into your function, you want to “call” it inside the function’s prompt
v
Ahh nice. thanks that worked!
v
btw, i think you can also use
ctx
in any template_string as well!
you just need to call the template string in your prompt