Class RuleDocumentValidator
- Namespace
- IntentSharp.Guardrails
- Assembly
- IntentSharp.Guardrails.dll
The validator of the guardrail documents: the manifest, rule files and their compiled companions. Registered with the client's document validators (WithGuardrailFiles(IntentClientBuilder, IDocumentStore, params string[]) and AddGuardrails(IServiceCollection, IDocumentStore, params string[]) register it), so an edit through the edit seam, or an edit of a working copy a FolderDocumentStore takes in, is checked before it runs: a version that does not load is LoadsCleanly false with its problems and is never stored as the running version (SI-8), and a version that loads reports what it changes and whether it widens access.
public sealed class RuleDocumentValidator : IDocumentValidator
- Inheritance
-
objectRuleDocumentValidator
- Implements
- Inherited Members
-
object.Equals(object)object.Equals(object, object)object.GetHashCode()object.GetType()object.ReferenceEquals(object, object)object.ToString()
- Extension Methods
Remarks
A version does not load for the reasons DocumentGuardrailSource refuses one: it does not parse, it is not
the document's shape, a rule has no kind or two, names a kind that is not registered (a custom kind's name contains a
dot) or gives a kind an argument it cannot take, a rule on a security subject is detect-only (SI-3), a key names a
literal secret (SI-7), or a settings: value is one its setting cannot take.
A version that loads is compared with the running one, rule by rule (by id) and setting by setting; every
difference is a SettingChange, named <set>.rules.<id>.allow for a changed allow list,
<set>.rules.<id> for a rule added, removed or otherwise changed, and
<set>.settings.<name> for a setting. WidensSecurity is true, with the
subject or setting in WidenedSubjects, when on a security subject an allow list gains an entry
("*" and "@described" included) or a new allow rule allows a value no allow rule named before, a deny
list loses an entry, an enforced rule is removed or made detect-only, a range or count is loosened, or any other kind's
argument changes; when a security setting becomes "unlimited" or larger, or turns from false to true; and when
one of the ordinary limits rules.patternTimeout, environment.handlerTimeout, client.maxAttempts,
client.maxModelCalls, client.maxInputChars, client.timeout and
environment.maxRecompilesPerHour becomes "unlimited" or larger than the running version's value or,
when the running version does not set it, than the value that applies without the file: its code value in
CodeSettings, else, for client.maxAttempts, client.maxModelCalls,
client.maxInputChars and client.timeout, the IntentClientOptions value of the client the
validator was added to (a DefaultTimeout of null is "unlimited"), else its
library default. The validator that WithGuardrailFiles and AddGuardrails add reads those options when it
assesses an edit, so a value set on them later counts; one created with this class's constructor knows no client and
compares a limit that only the client options set with its library default. Those
limits stay ordinary settings, so a file may still remove them. A
subject declared nowhere the validator can see may be a target's security subject, so a widening on it is flagged too.
A narrowing never widens. A new document is compared with nothing, so whatever it allows on a security subject widens.
A rule file whose set: changes, or whose target: changes from a target to another or to none, moves its
rules onto checks they did not govern: what it allows widens as in a new document, and a set: change also
widens every subject an enforced rule of the running version guarded, since the old set name may then be served by
another document; a companion whose set: changes is treated the same way. For the manifest, a document added
at the end of the list or removed from its end is a change, never a widening; any other change to the list may hand
a set name to another document (with the setting rules.ambiguousSet set to firstWins, the first
document listed that defines a name serves it), so it widens, named documents in
WidenedSubjects.
A widening applies like any other edit unless a writer of your own holds it (WithEditWriter(Func<IEditWriter, IEditWriter>)); the flag is what such a writer reads.
Constructors
- RuleDocumentValidator(GuardrailSourceOptions?)
Creates the validator.
Methods
- AssessAsync(DocumentId, string?, string, CancellationToken)
Assesses a proposed version of a guardrail document against the running one; see the class remarks.
- Handles(DocumentId)
True for the manifest (any of its spellings), for a rule file (a name ending in
.rules.json,.rules.yamlor.rules.yml) and for a compiled companion (.rules.compiled.json).