Charles Sanders Peirce’s seminal paper, “The Law of Mind” (1892), from which much of his philosophy can be derived, has a passage that is particularly pertinent to the concept of a rule of grammar, viz.: “To say that mental phenomena are governed by law does not mean merely that they are describable by a general formula; but that there is a living idea, a conscious continuum of feeling, which pervades them, and to which they are docile.” When it comes to language, of course, one can fairly advert to an attenuation of the “continuum of feeling” because when we speak we are typically not conscious of the habits that constitute grammatical rules even as we follow the laws that govern the mental phenomena underlying speech.
Although contemporary standard languages all have written codes that one can turn to when in doubt, no speaker in ordinary discourse needs to consult the canon of rules that exist in written sources in order to be able to use a language, which is to say that the rules are already immanent in one’s consciousness––just as they are in speech. The set of habits that transpire through speech has its counterpart in consciousness. That is what assures regularity, hence ease of linguistic communication, between speakers.
Variation between individual sets of speech habits can generally not exceed the bounds of the rules of a particular grammar. In a homogeneous speech community, all members who have mastered the language adhere to the rules as a matter of course. Where violations of the contemporary standard occur, they are generally due to imperfect learning rather than to dialectal deviation.
Apropos, in contemporary media language one often hears such spontaneous violations, even when their utterers are otherwise speakers of the standard. The extent to which errors matter to interlocutors or hearers depends on a variable sensitivity to what Peirce expressed (above) when he cited “a conscious continuum of feeling” as the “living idea” that pervades the law of mind.