You can only call
to_candid on shared types, not arbitrary generic types.
We don’t currently have a way to constrain generic types to be shareable in a nice way. Motoko Sharable Generics
It seems like it might take a while to add this feature. I will have to figure out a workaround solution. Thanks for your help and for sharing the link.