Use the OpenAI API/SDK for function calling instead of rolling your own inside the prompt.