# SafeLLamaGrammarHandle Namespace: LLama.Native A safe reference to a `llama_grammar` ```csharp public class SafeLLamaGrammarHandle : SafeLLamaHandleBase, System.IDisposable ``` Inheritance [Object](https://docs.microsoft.com/en-us/dotnet/api/system.object) → [CriticalFinalizerObject](https://docs.microsoft.com/en-us/dotnet/api/system.runtime.constrainedexecution.criticalfinalizerobject) → [SafeHandle](https://docs.microsoft.com/en-us/dotnet/api/system.runtime.interopservices.safehandle) → [SafeLLamaHandleBase](./llama.native.safellamahandlebase.md) → [SafeLLamaGrammarHandle](./llama.native.safellamagrammarhandle.md)
Implements [IDisposable](https://docs.microsoft.com/en-us/dotnet/api/system.idisposable) ## Properties ### **IsInvalid** ```csharp public bool IsInvalid { get; } ``` #### Property Value [Boolean](https://docs.microsoft.com/en-us/dotnet/api/system.boolean)
### **IsClosed** ```csharp public bool IsClosed { get; } ``` #### Property Value [Boolean](https://docs.microsoft.com/en-us/dotnet/api/system.boolean)
## Methods ### **ReleaseHandle()** ```csharp protected bool ReleaseHandle() ``` #### Returns [Boolean](https://docs.microsoft.com/en-us/dotnet/api/system.boolean)
### **Create(IReadOnlyList<GrammarRule>, UInt64)** Create a new llama_grammar ```csharp public static SafeLLamaGrammarHandle Create(IReadOnlyList rules, ulong start_rule_index) ``` #### Parameters `rules` [IReadOnlyList<GrammarRule>](https://docs.microsoft.com/en-us/dotnet/api/system.collections.generic.ireadonlylist-1)
A list of list of elements, each inner list makes up one grammar rule `start_rule_index` [UInt64](https://docs.microsoft.com/en-us/dotnet/api/system.uint64)
The index (in the outer list) of the start rule #### Returns [SafeLLamaGrammarHandle](./llama.native.safellamagrammarhandle.md)
#### Exceptions [RuntimeError](./llama.exceptions.runtimeerror.md)
### **Create(LLamaGrammarElement**, UInt64, UInt64)** Create a new llama_grammar ```csharp public static SafeLLamaGrammarHandle Create(LLamaGrammarElement** rules, ulong nrules, ulong start_rule_index) ``` #### Parameters `rules` [LLamaGrammarElement**](./llama.native.llamagrammarelement**.md)
rules list, each rule is a list of rule elements (terminated by a LLamaGrammarElementType.END element) `nrules` [UInt64](https://docs.microsoft.com/en-us/dotnet/api/system.uint64)
total number of rules `start_rule_index` [UInt64](https://docs.microsoft.com/en-us/dotnet/api/system.uint64)
index of the start rule of the grammar #### Returns [SafeLLamaGrammarHandle](./llama.native.safellamagrammarhandle.md)
#### Exceptions [RuntimeError](./llama.exceptions.runtimeerror.md)