malli

Chris Chen 2025-12-04T11:56:18.976889Z

Is there a way to change Malli's JSONSchema transformer at the function level as an option? I've noticed some differences with Zod's behaviour which is causing some trouble with LLM structured output APIs. Specifically :multi transforms to oneOf but Zod's z.discriminatedUnion transforms to anyOf with the discriminator key marked as 'required'.

opqdonut 2025-12-04T11:58:05.426429Z

you can set the :json-schema property for a malli schema, and that'll get used instead of the programmatically generated one

opqdonut 2025-12-04T11:58:59.009519Z

you could also define your own :multi2 and then add a (defmethod malli.json-schema/accept :multi2 ...) and extend the generation that way

opqdonut 2025-12-04T11:59:50.176349Z

in the general case malli can't do what you ask, since the :multi :dispatch can be an arbitrary function

👍 1
opqdonut 2025-12-04T12:00:04.603059Z

I guess we could detect the common special case where it is a literal kw....

👀 1
opqdonut 2025-12-04T12:03:50.777189Z

could you file an issue with some examples of malli & zod outputs? this might interest others as well.

Chris Chen 2025-12-04T12:04:51.560539Z

Sure nws