Ad-libbing was allowed by actors.
Once the actors got comfortable with their characters, filmmakers allowed them to ad-lib lines as long as they communicated the basic point. The funniest story is when Tom Felton, who played Draco Malfoy, said, “I didn’t know you could read” to his friend Goyle. That was not the line. Felton forgot the real one.