core: Add preconditions to generator function

This helps static analysis.