The scene with the Genie consoling Princess Jasmine while Aladdin is away at the lair of the forty thieves, was completely improvised by Robin Williams.
After a contract dispute with the Disney company over likeness rights, Robin Williams agreed to return for this film as the voice of the Genie ,reportedly for a $1 million salary after he received an apology from Joe Roth for Disney breaching an agreement not to use his voice to merchandise products inspired by Aladdin (1992). As a result, many of the ideas and gags that were not used in "Aladdin" could be retried in the making of this film. Dan Castellaneta had actually recorded all the dialogue of the Genie for this film, as he did with the previous sequel, but his recording session was not used when Williams agreed to reprise his role.
Among the Genie's many transformations is an old, grandmotherly woman, clearly meant to be Mrs. Doubtfire, the title character played by Robin Williams in Mrs. Doubtfire (1993). The character originated as Andy Kaufman's grandmother at his famous Carnegie Hall show, and was adapted for the movie.
Sir Sean Connery was originally cast as Cassim, but scheduling conflicts with another film forced him to drop out of the role. Cassim's appearance was based on Connery's rather than that of the voice actor who replaced him, John Rhys-Davies, his co-star in Indiana Jones and the Last Crusade (1989); another film centering around an estranged father and son chasing villains in search of a supernatural treasure that ultimately is discarded in favor of their renewed relationship.
The first idea for this storyline involved a villain from the Aladdin (1994) television series named Mozenrath. The plot would reveal that the hero and villain were brothers. However, according to one of the writers, everyone thought they should steer away from the television show. That and the fact that they couldn't get in touch with Jonathan Brandis (Mozenrath's voice), prompted writers to move on to another relative of Aladdin's - his father.