How to determine if people behave optimally with a generic utility function?

I have a some real-world data and a real-world choice for which I know the optimum solution is something like $$y^* = u(x)$$, where $$u(.)$$ is some utility function. I have data on $$y$$ and $$x$$, so if I knew $$u(.)$$, I could tell if people are behaving optimally (given the objective function). If I knew that $$u(x) = ln(x)$$ or $$u(x) = \sqrt{x}$$ then I could solve for the optimum, but I feel like it's cheating to assume a functional form for preferences. I do feel like it's reasonable to assume that $$u(x)$$ is continuous, that $$u'(x) > 0$$, and $$u''(x) < 0$$, but beyond that I'm uncomfortable with specifying the utility function. Is there any way, given data on $$y$$ and $$x$$, that economists have for deciding if a behavior is optimal given a generic utility function?

There is a whole literature on revealed preference analysis that looks at the testable implications on choice (consumption) data without imposing any functional form on the utility function. Is this what you are referring to?

Some key references:

• Samuelson (1948), "Consumption theory in terms of revealed preference", Economica, 15, 243-253
• Houthakker (1950), "Revealed preference and the utility function", Economica, 159-174
• Richter (1966), "Revealed preference theory", Econometrica, 34, 635-645
• Afriat (1967), "the construction of utility functions from expenditure data", International Economic Review, 8, 67-77
• Varian (1982), "The nonparametric approach to demand analysis", Econometrica, 50, 945-974
• Diewert (1973), "Afriat and revealed preference theory", Review of Economic Studies, 40, 419-425

Some overview articles or books:

• Varian (2006), "Revealed preference", in: Samuelson Economics and the twenty-first century", Oxford University Press
• Echenique and Chambers (2016), "Revealed preference theory", Cambridge University Press
• Crawford and De Rock (2014), "Empirical revealed preference theory", Annual review of Economics, 2014, 503-524
• Demuynck and Hjertstrand (2020), "Samuelson's approach to Revealed preference theory, some recent advances", in: Paul Samuelson: master of modern economics, Palgrave-Macmillan