Namespace IntentSharp.Guardrails
Classes
- DocumentGuardrailSource
The guardrail source over rule files in an IDocumentStore: the rule files a manifest document lists, each one rule set, with the rules of its compiled companion after its own. Pass it to WithGuardrails(IGuardrailSource, params string[]), or let WithGuardrailFiles(IntentClientBuilder, IDocumentStore, params string[]) or AddGuardrails(IServiceCollection, IDocumentStore, params string[]) create it. Every document is versioned by the store, so an edit applies to the next check and a revert brings the previous rules back.
- GuardrailBuilderExtensions
Makes a client from IntentClientBuilder check the rule files a document store holds:
var store = new FolderDocumentStore("policy"); using var client = new IntentClientBuilder() .UseProviderOptions(store) .WithDocumentStore(store) .WithGuardrailFiles(store, "orders-data") .Build();
- GuardrailCoverage
The gate every guarded operation passes before it proceeds: a target before it executes, the client before a guarded call, and an application at a checkpoint of its own, each after CheckAsync(GuardrailCheckpoint, SubjectValues, IReadOnlyList<string>, CancellationToken).
- GuardrailDecision
The outcome of one guardrail check: whether the operation may proceed, the sets it was checked against, the violations and detections, the settings the operation runs under, and a stamp per set. Pass it to Ensure(GuardrailDecision) before the operation proceeds.
- GuardrailDeclarations
The settings and subjects declared on an IntentClientBuilder with AddSetting(SettingDescriptor) and AddSubject(SubjectDescriptor), in the order they were declared, as Build() hands them to OnBuild. A guardrail source that reads rules from files uses them to know the settings a
settings:block may set and the subjects its rules may name.
- GuardrailFileSet
The result of reading rule files with Parse(IReadOnlyList<KeyValuePair<string, string>>, GuardrailSourceOptions?): the rule sets that loaded, and the problems of the documents that did not.
- GuardrailFiles
Reads rule files from text, with the same binder DocumentGuardrailSource uses: to test a rule file in a unit test, or to keep rule files in a store of your own and serve them through an IGuardrailSource you write. No manifest is needed: every document given is read.
- GuardrailKindContext
What a kind may read about the operation being checked, beside the value and the rule's argument.
- GuardrailKindResult
The verdict of a IGuardrailKind on one value.
- GuardrailLoadException
Thrown when rule files cannot be used: by ParseOrThrow(IReadOnlyList<KeyValuePair<string, string>>, GuardrailSourceOptions?) when a document does not load, and by Current when a pinned document's hash differs from the expected one or the store could not be read at the first load. The message lists every problem as
path:line: message.
- GuardrailOptions
How a client checks guardrails: the source of the rule sets, the sets it applies by default, and what it declares beyond the library's core subjects, settings and kinds. Pass it to WithGuardrails(GuardrailOptions), or register it in the service collection for a client built by
AddIntentSharp. The client reads these options when it is built; a later change to them does not reach a built client.
- GuardrailPolicyException
Thrown by Ensure(GuardrailDecision) when a guardrail decision does not allow the operation. The operation did not run; Decision says why.
- GuardrailRule
One rule of a GuardrailSet: a subject, the kind that checks it and the kind's argument. Built-in kinds are
allowanddeny(a list of values),pattern(a regular expression),rangeandcount(an object withminandmax); a custom kind's name contains a dot.
- GuardrailServiceCollectionExtensions
Registers guardrail rule files for the IntentClient that
AddIntentSharpbuilds:services.AddDocumentStore("policy"); // the store the client keeps its documents in services.AddGuardrails(store, "orders-data"); // the rule files that store's manifest lists services.AddIntentSharp(configuration);The client reads the registered source, options, kinds, format and validator when it is built, so it checks the rule files' sets and validates every edit of them. Rules a rule file writes as intent compile only when AddRuleCompilation(IServiceCollection, Action<RuleCompileOptions>?) is called too (experimental,
INTENTSHARP001).
- GuardrailSet
A named rule set as a source supplies it: where it came from, the checkpoint it is for, its rules (written by a person and compiled from intent, together) and its settings. A check names the sets it applies.
- GuardrailSourceOptions
Settings for reading rule files from a document store: where the manifest is, which documents are pinned to a hash, the kinds, subjects and settings a rule file may name beyond the library's own, and the code layer of the settings. Used by DocumentGuardrailSource, RuleDocumentValidator and GuardrailFiles, which copy the values when they are created, so a later change does not reach them.
- GuardrailStamp
Records which version of a named rule set a decision was made under: the set, the author's label, the document and its version, the content hash and the snapshot's revision.
- GuardrailViolation
A rule that failed in a check: an enforced rule's failure is a violation, a detect-only rule's a detection. Message is what may go back to the model; Detail is the full text, for results and logs.
- InMemoryGuardrailSource
A guardrail source over rule sets written in code: one snapshot, which never changes, so a client or a target runtime can be ruled with no rule file and no document store, for example
builder.WithGuardrails(new InMemoryGuardrailSource(ordersSet), "orders-data"). The checks apply its sets as they apply sets read from files and fail closed the same way: a check whose sets leave a required subject uncovered, or that meets a detect-only rule on a security subject, is refused. The source is its own snapshot.
- RuleCompileExtensions
Turns on the compilation of the rules a client's rule files write as intent, which is off until one of these is called. On the builder:
var store = new FolderDocumentStore("policy"); using var client = new IntentClientBuilder() .UseProviderOptions(store) .WithDocumentStore(store) .WithGuardrailFiles(store, "orders-data") .WithRuleCompilation(store) .Build();For the client
AddIntentSharpbuilds:services.AddDocumentStore(store); services.AddGuardrails(store, "orders-data"); services.AddRuleCompilation(); services.AddIntentSharp(configuration);
- RuleCompileHandler
Compiles rules written as intent into a compiled companion: when a target's schema changes, or the
intent:text of a rule file changes, the rule sets written for that target are compiled again by the model, through the client'smaintenancerole, into fixed rules of the kinds the client knows, and the result is submitted asrules/<name>.rules.compiled.jsonthrough the client's edit seam, so it takes effect by default. No model decides anything when an operation is checked: the gate evaluates the compiled rules like the authored ones. Compilation is off until the developer turns it on: register the handler with WithRuleCompilation(IntentClientBuilder, IDocumentStore, Action<RuleCompileOptions>?) on the builder, or with AddRuleCompilation(IServiceCollection, Action<RuleCompileOptions>?) beside AddGuardrails(IServiceCollection, IDocumentStore, params string[]) for a client built byAddIntentSharp.
- RuleCompileOptions
Settings for compiling rules written as intent (RuleCompileHandler): which compile intent runs, through which provider role, and where the manifest that lists the rule files is. The handler copies the values when it is created, so a later change does not reach it.
- RuleDocumentValidator
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.
- SettingDescriptor
Declares a setting: its name, the values it takes, and what it resolves to when nothing sets it. A setting resolves to a file's value, else the code value, else, for an ordinary setting, LibraryDefault and, for a security setting, FailClosedValue; there is no ceiling and no comparison between the layers. The library declares the core settings; add your own with AddSetting(SettingDescriptor) or Settings.
- SettingValue
A setting as one check resolved it: its value, whether the value removes the limit, and where it came from. Test IsUnlimited first: the typed readers return false for an unlimited value.
- ShadowDifference
A rule whose verdict in a check differs between the running version of its rule document and a version run side by side (Shadows). It names the rule, its subject and both verdicts, and never a subject's value, a rule's pattern or values, or a message, so it is safe to log and to keep.
- ShadowVersion
A version of a rule document to run side by side with the running version: typically a candidate saved with Activate false. List it in Shadows; every check evaluates its rules detect-only beside the running rules, on the same subjects, and reports where the verdicts differ in ShadowDifferences. It never decides anything. Promote it with ActivateAsync(DocumentId, long, CancellationToken); the library never promotes a version on its own.
- SubjectDescriptor
Declares a subject: its name, the checkpoint that supplies it, and how the check treats it. The library declares the core subjects (CoreSubjects); a target or an application declares its own through Subjects or Subjects. A rule on a subject that no descriptor declares is a violation when the rule is enforced.
- SubjectValues
What a caller hands to one guardrail check: the subjects' values by name, each a JSON value or an explicit unknown marker, plus what the check needs from the caller's context: the entities of the current description (what
"@described"in anallowlist stands for), subjects the caller declares beyond the client's, and the caller's own setting values for this check. Build one per check; an instance is not safe to change from several threads.
- YamlDocumentFormat
The YAML format for the documents of an IDocumentStore: reads
.yamland.ymldocuments, such as rule files, the guardrail manifest, settings or provider files written in YAML, into a JSON tree with the line of every node and key. AddGuardrails(IServiceCollection, IDocumentStore, params string[]) and WithGuardrailFiles(IntentClientBuilder, IDocumentStore, params string[]) register it for the client; add it yourself with AddDocumentFormat(IDocumentFormat).
Structs
- GuardrailCheckpoint
A place in an operation where guardrail rules are checked, by name. The names are open: the six built in here are the ones the library raises, and a target or an application may raise a checkpoint of its own and check it with CheckAsync(GuardrailCheckpoint, SubjectValues, IReadOnlyList<string>, CancellationToken). Two checkpoints are equal exactly when their names are equal, compared ordinally (case-sensitive).
- SubjectName
The name of a fact a checkpoint hands to the guardrail rules, such as
data.entities. Names are open and written<checkpoint>.<name>by convention; targets and applications add their own. Two names are equal exactly when their values are equal, compared ordinally (case-sensitive).
Interfaces
- IGuardrailKind
Checks a subject's value against a rule's argument. The built-in kinds are
allow,deny,pattern,rangeandcount; implement this interface for a kind of your own and add it through Kinds. A kind is deterministic: the same value and argument give the same verdict.
- IGuardrailShadowSource
The optional capability of an IGuardrailSource to read other versions of its rule documents, so a client can run them side by side with the running version (Shadows), and to keep the running tally of what they changed. Implement it beside IGuardrailSource on the same object; a client with shadows and a source without it is not built. The IntentSharp.Guardrails package's rule file source implements it.
- IGuardrailSnapshot
The rule sets of a IGuardrailSource at one moment. A snapshot never changes; a new version of a rule set comes in a new snapshot.
- IGuardrailSource
Supplies the guardrail rule sets a client checks. Each check reads Current once and evaluates that one snapshot, so a change applies from the next check and never in the middle of one. Implement it to keep rule sets in a technology of your own; the IntentSharp.Guardrails package supplies one over rule files.
Enums
- SettingKind
The kind of value a setting takes, which decides the values it accepts.
- SettingSource
Where a resolved setting's value came from.