Jamie
12/18/2025, 5:51 PMAnswer in JSON using any of these schemas:
string or {
data: {
// Read the contents of a file.
tool_name: "read_file",
// Path to the file to read
file_path: string,
} or ...
(the DynamicContainer has a single field and the field type is a union).
A dumb model returns {"string": "your answer is ..."} and the function returns this string that happens to contain json, not "your answer is ...".
I was thinking of "manually" constructing a prompt:
Answer with a string or a JSON object with this schema:
{
data: { ...
} or { ...
} or ...
}
Ok. That is one goal.
The other idea is apparently some Anthropic tool APIs are defined implicitly where just by specifying the tool name, the model knows the arguments and argument types etc. so if I have a matching return type to catch the tool call, it should work, and I could omit most of the tool definition to save tokens, and I would presume the model is good at knowing when to call the tool. Here again I would be customizing the output format request. But if I am mixing built-in Anthropic functions and my own functions, I can't use ctx.output_format because it will fully specify all the tool APIs.
I am thinking I can construct the output format section of the prompt outside the BAML call (in Python) and pass it in, and just render it like any other variable. But if I have variable unions of types or deeply nested structures I can't have fixed strings and I need a way to generate fragments of the output_format from Python.
Does this make sense? Are these facilities available?greg (BAML)
12/19/2025, 5:00 PMnikitoshina
12/19/2025, 8:32 PMnikitoshina
12/19/2025, 8:33 PMJamie
12/20/2025, 6:28 AMJamie
12/20/2025, 6:34 AM---PROMPT---
system: Answer in with a plain string or to perform a tool call, return a JSON object obeying this schema:
{
data: {
// Read the contents of a file.
tool_name: "read_file",
// Path to the file to read
file_path: string,
} or {
// Write content to a file.
tool_name: "write_file",
// Path to the file to write
file_path: string,
// Content to write to the file
content: string,
} or {
// List the contents of a directory.
tool_name: "list_directory",
// Path to the directory to list
directory_path: string,
} or {
// Execute a shell command and return its output.
tool_name: "run_command",
// Command to execute (shell command string)
command: string,
},
}
user: there is a file in the current folder where the filename is a persons name. within that file is a number. what is that number?
---LLM REPLY---
<|start|>assistant<|channel|>commentary to=tool.run_command <|constrain|>json<|message|>{"command":"ls -1"}<|call|>
---Parsed Response (string)---
"{command: ls -1}"Vaibhav (BAML 🐑)
12/20/2025, 8:28 PMVaibhav (BAML 🐑)
12/20/2025, 8:29 PM