oyebahadur
05/04/2026, 4:03 PMfunctionToolCallbacks](https://www.promptfoo.dev/docs/providers/openai/#using-functions:~:text=and%20parameters.-,functionToolCallbacks,-A%20map%20of) is invoked with just the param string.
Since the callback has no information about the context, it is difficult to emulate the function as closely as one may like to the real implementation, during the eval.
Adding context (testCase.metadata or testCase.vars) allows [function callbacks](https://www.promptfoo.dev/docs/providers/openai/#using-functions:~:text=and%20parameters.-,functionToolCallbacks,-A%20map%20of) to be somewhat stateful. Since there is little control over test case execution order in promptfoo, contextual callbacks cannot be used in cases where ordering is required. I'm not asking for that control.
The examples in the doc led me to try this workaround
json
{
type: "function",
function: {
name: "get_temperature",
parameters: {
type: "object",
properties: {
unit: {
type: "string",
enum: (vars) => vars.context_id,
}
},
}
}
}
It might work for the providers that fully support structured json_schema. However, I wasn't able to test this (my provider doesn't have this, it violated the schema and generated some nonsense string).
I'm curious to hear if this is worthy of inclusion in promptfoo. I'd be happy to contribute if some one can share some pointers.
PS: Congrats on the acquisition!ian
05/23/2026, 4:17 AM