diff --git a/mex/sources/k_order_welfare/k_order_welfare.cc b/mex/sources/k_order_welfare/k_order_welfare.cc
index 5ae3552534ebc1a2eedc0e6b076e1b6b0cdef942..711e4d90064a2daf34128c00fc1f3f9a3cf8b16e 100644
--- a/mex/sources/k_order_welfare/k_order_welfare.cc
+++ b/mex/sources/k_order_welfare/k_order_welfare.cc
@@ -87,6 +87,8 @@ extern "C" {
   void mexFunction(int nlhs, mxArray *plhs[],
                    int nrhs, const mxArray *prhs[])
   {
+    if (nlhs != 1 || nrhs != 3)
+      mexErrMsgTxt("Must have exactly 3 input arguments and 1 output argument");
 
     const mxArray *dr_mx = prhs[0];
     const mxArray *M_mx = prhs[1];