Recommended strategy to handle invalid tool input #7110
-
|
If the LLM returns a tool call with an object that doesn't respect the tool input schema, a I'm trying to see what the possibilities are to make the LLM retry the tool call. I'm experimenting with Would you have any other suggestion? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 6 replies
-
|
Both of those are valid. As are:
|
Beta Was this translation helpful? Give feedback.
-
|
@stephentoub would it make sense to push some of that logic into MEAI? LLM calling with improper schema is quite common (incorrect enum value, string instead of int, ...), so that seems like a shared concern. As offering good standard behavior may be difficult, one possible solution would be to still call the tool when the marshalling of the argument fails, to let the developper handle it as they see fit. Similarly to how So a tool implementation could look like: // in MEAI
public class AiArgumentDeserializationException(string Parameter, Exception Inner) : Exception;
// in Custom agent code
public enum Foo{Bar}
public string MyTool(Foo foo, AIFunctionArguments args, AiArgumentDeserializationException ex){
if(ex!= null){
//developper has access to the inner exception and the raw argument and can shape its message how it wants
return $"Oups, looks like your {ex.Parameter} argument's value {args[ex.Parameter]?.ToString()} is invalid: {ex.Inner.Message}";
}
//happy path
return "success";
} |
Beta Was this translation helpful? Give feedback.
Both of those are valid. As are: