https://www.boundaryml.com logo
🟡 Challenges with LLM and BAML Output Format
# questions
c
Feel like when user OpenAI with web search, the LLM output is a bit hard to comform with the BAML output format. Usually it just return as string, causing schema validation error. wondering if there is trick to do this.
v
Do you put ctx.output_format in the system prompt or as the last part of content
c
I think i did both like
Copy code
{% endif %}

      Extract the following data:
      {{ _.role('system') }}
      {{ ctx.output_format }}
  "#
}
# end of file
Copy code
function Testsss(

  messages: string[],

) -> FrontOfHouseConversation {
  client OpenaiGPT41Search
  prompt #"
      Doing web search to figure out parking rate for the query: 
      {{ messages  }}


      Extract the following data:
      {{ _.role('system') }}
      {{ ctx.output_format }}
  "#
}

test testsetsts {
  functions [Testsss]
  args {
    messages [
      #"user What is the parking rate for the Seattle airport?"#
    ]
  }
}
Copy code
class FrontOfHouseConversation {
  agent_response string @description(#"
    The response to the traveler's most recent input, directive or question.
  "#)
  last_message_topic string @description(#"the topic that best matches the traveler's most recent input, directive or question."#)
}
Copy code
client<llm> OpenaiGPT41Search {
  provider openai-responses
  options {
    api_key env.OPENAI_API_KEY
    model "gpt-4.1"
    allowed_roles ["system", "developer", "user", "assistant", "tool"]
    tools [
      {
        type "web_search_preview"
      }
    ]    
  }
}
b
Thanks for sharing the repro! Can I ask what the response that comes back is? (I'm getting the release out right now, otherwise I'd try to repro myself.)
v
perfect, I think this may be solved hopefully soon! @Antonio Sarosi (BAML 🐑) has been thinking about how we can add native tool calling support here. which will perhaps make this better
c
ah. pretty cool
seems still having issue with structured output.
I am on 0.209.0