[backend] Handle whitespace during sentence generation