Class LiteRtConstraint
- Namespace
- LiteRtLmSharp
- Assembly
- LiteRtLmSharp.dll
A per-send output constraint enforced during sampling by the conversation's ConstraintProvider: tokens that cannot lead to a valid completion of the pattern are masked out, so the model can only emit conforming output. Set on Constraint; requires the conversation to have been created with LlGuidance. Requires native LiteRT-LM v0.15.0+.
public sealed record LiteRtConstraint : IEquatable<LiteRtConstraint>
- Inheritance
-
LiteRtConstraint
- Implements
- Inherited Members
Remarks
Maps to the C API litert_lm_conversation_optional_args_set_constraint.
Properties
Pattern
The constraint pattern: a regular expression or a JSON Schema document, per Type. Must be non-empty.
public required string Pattern { get; init; }
Property Value
Exceptions
- ArgumentException
The value is null or whitespace.
Type
How to interpret Pattern. Must be a defined member — an out-of-range
value (including the unset default) is rejected here rather than passed to the native
layer, whose constraint compiler does not police the enum (an undefined value reaches
undefined behavior in the LlGuidance bridge).
public required LiteRtConstraintType Type { get; init; }
Property Value
Exceptions
- ArgumentOutOfRangeException
The value is not Regex or JsonSchema.
Methods
FromJsonSchema(string)
A constraint forcing output that conforms to the given JSON Schema document.
public static LiteRtConstraint FromJsonSchema(string schemaJson)
Parameters
schemaJsonstring
Returns
FromRegex(string)
A constraint forcing output that matches the given regular expression.
public static LiteRtConstraint FromRegex(string regex)
Parameters
regexstring