Play by the Type Rules: Inferring Constraints for LLM Functions in Declarative Programs