This is a very common question. Here is a good explanation provided by bostonist.com:
The owner of a dog is responsible for damages caused by that dog to people or property, and if a dog bites a person, it doesn’t matter what precautions the owner took, unless the person was “teasing, tormenting, or abusing” the dog, or trespassing. People who are “keepers” of a dog owned by someone else also can’t sue the owner for damages. That means veterinarians and folks who live with, walk, and feed a dog although it was purchased by someone else. And children under seven who are attacked by dogs are presumed not to be teasing, tormenting, abusing, or trespassing. Also, under a 1974 Appeals Court decision, a properly trained attack dog can be considered a dangerous weapon, and its owner can be charged with assault and battery with a dangerous weapon in the right circumstances. Most garden-variety citations for unruly or unleashed dogs, though, are based in the law of a particular city or town.