@solvers-hub/llm-json 0.1.5 → 0.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +116 -50
- package/dist/src/array-extractor.js +6 -1
- package/dist/src/corrector.js +11 -12
- package/dist/src/extractor.d.ts +9 -1
- package/dist/src/extractor.js +36 -26
- package/dist/src/types.d.ts +44 -0
- package/dist/src/validator.d.ts +27 -0
- package/dist/src/validator.js +76 -0
- package/docs/assets/navigation.js +1 -1
- package/docs/assets/search.js +1 -1
- package/docs/classes/LlmJson.html +5 -5
- package/docs/index.html +10 -2
- package/docs/interfaces/ExtractOptions.html +7 -2
- package/docs/interfaces/ExtractResult.html +5 -3
- package/docs/interfaces/JsonBlock.html +6 -6
- package/docs/interfaces/JsonParseError.html +4 -4
- package/docs/interfaces/SchemaDefinition.html +6 -0
- package/docs/interfaces/ValidationResult.html +10 -0
- package/docs/modules.html +2 -0
- package/docs-md/README.md +71 -22
- package/docs-md/classes/LlmJson.md +7 -7
- package/docs-md/interfaces/ExtractOptions.md +21 -1
- package/docs-md/interfaces/ExtractResult.md +15 -2
- package/docs-md/interfaces/JsonBlock.md +5 -5
- package/docs-md/interfaces/JsonParseError.md +3 -3
- package/docs-md/interfaces/SchemaDefinition.md +36 -0
- package/docs-md/interfaces/ValidationResult.md +62 -0
- package/docs-md/modules.md +2 -0
- package/examples/array-example.ts +69 -0
- package/examples/example.ts +101 -0
- package/examples/schema-validation-example.ts +140 -0
- package/examples/schema-validation-examples.ts +248 -0
- package/package.json +52 -48
@@ -1,8 +1,8 @@
|
|
1
1
|
<!DOCTYPE html><html class="default" lang="en"><head><meta charSet="utf-8"/><meta http-equiv="x-ua-compatible" content="IE=edge"/><title>JsonParseError | @solvers-hub/llm-json</title><meta name="description" content="Documentation for @solvers-hub/llm-json"/><meta name="viewport" content="width=device-width, initial-scale=1"/><link rel="stylesheet" href="../assets/style.css"/><link rel="stylesheet" href="../assets/highlight.css"/><script defer src="../assets/main.js"></script><script async src="../assets/icons.js" id="tsd-icons-script"></script><script async src="../assets/search.js" id="tsd-search-script"></script><script async src="../assets/navigation.js" id="tsd-nav-script"></script></head><body><script>document.documentElement.dataset.theme = localStorage.getItem("tsd-theme") || "os";document.body.style.display="none";setTimeout(() => app?app.showPage():document.body.style.removeProperty("display"),500)</script><header class="tsd-page-toolbar"><div class="tsd-toolbar-contents container"><div class="table-cell" id="tsd-search" data-base=".."><div class="field"><label for="tsd-search-field" class="tsd-widget tsd-toolbar-icon search no-caption"><svg width="16" height="16" viewBox="0 0 16 16" fill="none"><use href="../assets/icons.svg#icon-search"></use></svg></label><input type="text" id="tsd-search-field" aria-label="Search"/></div><div class="field"><div id="tsd-toolbar-links"></div></div><ul class="results"><li class="state loading">Preparing search index...</li><li class="state failure">The search index is not available</li></ul><a href="../index.html" class="title">@solvers-hub/llm-json</a></div><div class="table-cell" id="tsd-widgets"><a href="#" class="tsd-widget tsd-toolbar-icon menu no-caption" data-toggle="menu" aria-label="Menu"><svg width="16" height="16" viewBox="0 0 16 16" fill="none"><use href="../assets/icons.svg#icon-menu"></use></svg></a></div></div></header><div class="container container-main"><div class="col-content"><div class="tsd-page-title"><ul class="tsd-breadcrumb"><li><a href="../modules.html">@solvers-hub/llm-json</a></li><li><a href="JsonParseError.html">JsonParseError</a></li></ul><h1>Interface JsonParseError</h1></div><section class="tsd-panel tsd-comment"><div class="tsd-comment tsd-typography"><p>Error information for JSON parsing failures.</p>
|
2
|
-
</div><div class="tsd-comment tsd-typography"></div></section><div class="tsd-signature"><span class="tsd-signature-keyword">interface </span><span class="tsd-kind-interface">JsonParseError</span> <span class="tsd-signature-symbol">{ </span><br/><span> </span><a class="tsd-kind-property" href="JsonParseError.html#message">message</a><span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">string</span><span class="tsd-signature-symbol">; </span><br/><span> </span><a class="tsd-kind-property" href="JsonParseError.html#position">position</a><span class="tsd-signature-symbol">?: </span><span class="tsd-signature-type">number</span><span class="tsd-signature-symbol">; </span><br/><span> </span><a class="tsd-kind-property" href="JsonParseError.html#raw">raw</a><span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">string</span><span class="tsd-signature-symbol">; </span><br/><span class="tsd-signature-symbol">}</span></div><aside class="tsd-sources"><ul><li>Defined in <a href="https://github.com/solvers-hub/llm-json/blob/
|
2
|
+
</div><div class="tsd-comment tsd-typography"></div></section><div class="tsd-signature"><span class="tsd-signature-keyword">interface </span><span class="tsd-kind-interface">JsonParseError</span> <span class="tsd-signature-symbol">{ </span><br/><span> </span><a class="tsd-kind-property" href="JsonParseError.html#message">message</a><span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">string</span><span class="tsd-signature-symbol">; </span><br/><span> </span><a class="tsd-kind-property" href="JsonParseError.html#position">position</a><span class="tsd-signature-symbol">?: </span><span class="tsd-signature-type">number</span><span class="tsd-signature-symbol">; </span><br/><span> </span><a class="tsd-kind-property" href="JsonParseError.html#raw">raw</a><span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">string</span><span class="tsd-signature-symbol">; </span><br/><span class="tsd-signature-symbol">}</span></div><aside class="tsd-sources"><ul><li>Defined in <a href="https://github.com/solvers-hub/llm-json/blob/c66e07bf56dff5952768d1bbe7ca7221c8d2192d/src/types.ts#L112">types.ts:112</a></li></ul></aside><section class="tsd-panel-group tsd-index-group"><section class="tsd-panel tsd-index-panel"><details class="tsd-index-content tsd-index-accordion" open><summary class="tsd-accordion-summary tsd-index-summary"><h5 class="tsd-index-heading uppercase" role="button" aria-expanded="false" tabIndex="0"><svg width="16" height="16" viewBox="0 0 16 16" fill="none"><use href="../assets/icons.svg#icon-chevronSmall"></use></svg> Index</h5></summary><div class="tsd-accordion-details"><section class="tsd-index-section"><h3 class="tsd-index-heading">Properties</h3><div class="tsd-index-list"><a href="JsonParseError.html#message" class="tsd-index-link"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="../assets/icons.svg#icon-1024"></use></svg><span>message</span></a>
|
3
3
|
<a href="JsonParseError.html#position" class="tsd-index-link"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="../assets/icons.svg#icon-1024"></use></svg><span>position?</span></a>
|
4
4
|
<a href="JsonParseError.html#raw" class="tsd-index-link"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="../assets/icons.svg#icon-1024"></use></svg><span>raw</span></a>
|
5
5
|
</div></section></div></details></section></section><section class="tsd-panel-group tsd-member-group"><h2>Properties</h2><section class="tsd-panel tsd-member"><a id="message" class="tsd-anchor"></a><h3 class="tsd-anchor-link"><span>message</span><a href="#message" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h3><div class="tsd-signature"><span class="tsd-kind-property">message</span><span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">string</span></div><div class="tsd-comment tsd-typography"><p>The original error message.</p>
|
6
|
-
</div><div class="tsd-comment tsd-typography"></div><aside class="tsd-sources"><ul><li>Defined in <a href="https://github.com/solvers-hub/llm-json/blob/
|
7
|
-
</div><div class="tsd-comment tsd-typography"></div><aside class="tsd-sources"><ul><li>Defined in <a href="https://github.com/solvers-hub/llm-json/blob/
|
8
|
-
</div><div class="tsd-comment tsd-typography"></div><aside class="tsd-sources"><ul><li>Defined in <a href="https://github.com/solvers-hub/llm-json/blob/
|
6
|
+
</div><div class="tsd-comment tsd-typography"></div><aside class="tsd-sources"><ul><li>Defined in <a href="https://github.com/solvers-hub/llm-json/blob/c66e07bf56dff5952768d1bbe7ca7221c8d2192d/src/types.ts#L116">types.ts:116</a></li></ul></aside></section><section class="tsd-panel tsd-member"><a id="position" class="tsd-anchor"></a><h3 class="tsd-anchor-link"><code class="tsd-tag ts-flagOptional">Optional</code> <span>position</span><a href="#position" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h3><div class="tsd-signature"><span class="tsd-kind-property">position</span><span class="tsd-signature-symbol">?:</span> <span class="tsd-signature-type">number</span></div><div class="tsd-comment tsd-typography"><p>The position in the JSON string where the error occurred.</p>
|
7
|
+
</div><div class="tsd-comment tsd-typography"></div><aside class="tsd-sources"><ul><li>Defined in <a href="https://github.com/solvers-hub/llm-json/blob/c66e07bf56dff5952768d1bbe7ca7221c8d2192d/src/types.ts#L126">types.ts:126</a></li></ul></aside></section><section class="tsd-panel tsd-member"><a id="raw" class="tsd-anchor"></a><h3 class="tsd-anchor-link"><span>raw</span><a href="#raw" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h3><div class="tsd-signature"><span class="tsd-kind-property">raw</span><span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">string</span></div><div class="tsd-comment tsd-typography"><p>The raw JSON string that failed to parse.</p>
|
8
|
+
</div><div class="tsd-comment tsd-typography"></div><aside class="tsd-sources"><ul><li>Defined in <a href="https://github.com/solvers-hub/llm-json/blob/c66e07bf56dff5952768d1bbe7ca7221c8d2192d/src/types.ts#L121">types.ts:121</a></li></ul></aside></section></section></div><div class="col-sidebar"><div class="page-menu"><div class="tsd-navigation settings"><details class="tsd-index-accordion"><summary class="tsd-accordion-summary"><h3><svg width="20" height="20" viewBox="0 0 24 24" fill="none"><use href="../assets/icons.svg#icon-chevronDown"></use></svg>Settings</h3></summary><div class="tsd-accordion-details"><div class="tsd-filter-visibility"><h4 class="uppercase">Member Visibility</h4><form><ul id="tsd-filter-options"><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-protected" name="protected"/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>Protected</span></label></li><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-private" name="private"/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>Private</span></label></li><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-inherited" name="inherited" checked/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>Inherited</span></label></li><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-external" name="external"/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>External</span></label></li></ul></form></div><div class="tsd-theme-toggle"><h4 class="uppercase">Theme</h4><select id="tsd-theme"><option value="os">OS</option><option value="light">Light</option><option value="dark">Dark</option></select></div></div></details></div><details open class="tsd-index-accordion tsd-page-navigation"><summary class="tsd-accordion-summary"><h3><svg width="20" height="20" viewBox="0 0 24 24" fill="none"><use href="../assets/icons.svg#icon-chevronDown"></use></svg>On This Page</h3></summary><div class="tsd-accordion-details"><a href="#message" class=""><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="../assets/icons.svg#icon-1024"></use></svg><span>message</span></a><a href="#position" class=""><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="../assets/icons.svg#icon-1024"></use></svg><span>position</span></a><a href="#raw" class=""><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="../assets/icons.svg#icon-1024"></use></svg><span>raw</span></a></div></details></div><div class="site-menu"><nav class="tsd-navigation"><a href="../modules.html"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="../assets/icons.svg#icon-1"></use></svg><span>@solvers-hub/llm-json</span></a><ul class="tsd-small-nested-navigation" id="tsd-nav-container" data-base=".."><li>Loading...</li></ul></nav></div></div></div><footer><p class="tsd-generator">Generated using <a href="https://typedoc.org/" target="_blank">TypeDoc</a></p></footer><div class="overlay"></div></body></html>
|
@@ -0,0 +1,6 @@
|
|
1
|
+
<!DOCTYPE html><html class="default" lang="en"><head><meta charSet="utf-8"/><meta http-equiv="x-ua-compatible" content="IE=edge"/><title>SchemaDefinition | @solvers-hub/llm-json</title><meta name="description" content="Documentation for @solvers-hub/llm-json"/><meta name="viewport" content="width=device-width, initial-scale=1"/><link rel="stylesheet" href="../assets/style.css"/><link rel="stylesheet" href="../assets/highlight.css"/><script defer src="../assets/main.js"></script><script async src="../assets/icons.js" id="tsd-icons-script"></script><script async src="../assets/search.js" id="tsd-search-script"></script><script async src="../assets/navigation.js" id="tsd-nav-script"></script></head><body><script>document.documentElement.dataset.theme = localStorage.getItem("tsd-theme") || "os";document.body.style.display="none";setTimeout(() => app?app.showPage():document.body.style.removeProperty("display"),500)</script><header class="tsd-page-toolbar"><div class="tsd-toolbar-contents container"><div class="table-cell" id="tsd-search" data-base=".."><div class="field"><label for="tsd-search-field" class="tsd-widget tsd-toolbar-icon search no-caption"><svg width="16" height="16" viewBox="0 0 16 16" fill="none"><use href="../assets/icons.svg#icon-search"></use></svg></label><input type="text" id="tsd-search-field" aria-label="Search"/></div><div class="field"><div id="tsd-toolbar-links"></div></div><ul class="results"><li class="state loading">Preparing search index...</li><li class="state failure">The search index is not available</li></ul><a href="../index.html" class="title">@solvers-hub/llm-json</a></div><div class="table-cell" id="tsd-widgets"><a href="#" class="tsd-widget tsd-toolbar-icon menu no-caption" data-toggle="menu" aria-label="Menu"><svg width="16" height="16" viewBox="0 0 16 16" fill="none"><use href="../assets/icons.svg#icon-menu"></use></svg></a></div></div></header><div class="container container-main"><div class="col-content"><div class="tsd-page-title"><ul class="tsd-breadcrumb"><li><a href="../modules.html">@solvers-hub/llm-json</a></li><li><a href="SchemaDefinition.html">SchemaDefinition</a></li></ul><h1>Interface SchemaDefinition</h1></div><section class="tsd-panel tsd-comment"><div class="tsd-comment tsd-typography"><p>Definition of a JSON schema for validation.</p>
|
2
|
+
</div><div class="tsd-comment tsd-typography"></div></section><div class="tsd-signature"><span class="tsd-signature-keyword">interface </span><span class="tsd-kind-interface">SchemaDefinition</span> <span class="tsd-signature-symbol">{ </span><br/><span> </span><a class="tsd-kind-property" href="SchemaDefinition.html#name">name</a><span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">string</span><span class="tsd-signature-symbol">; </span><br/><span> </span><a class="tsd-kind-property" href="SchemaDefinition.html#schema">schema</a><span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">object</span><span class="tsd-signature-symbol">; </span><br/><span class="tsd-signature-symbol">}</span></div><aside class="tsd-sources"><ul><li>Defined in <a href="https://github.com/solvers-hub/llm-json/blob/c66e07bf56dff5952768d1bbe7ca7221c8d2192d/src/types.ts#L22">types.ts:22</a></li></ul></aside><section class="tsd-panel-group tsd-index-group"><section class="tsd-panel tsd-index-panel"><details class="tsd-index-content tsd-index-accordion" open><summary class="tsd-accordion-summary tsd-index-summary"><h5 class="tsd-index-heading uppercase" role="button" aria-expanded="false" tabIndex="0"><svg width="16" height="16" viewBox="0 0 16 16" fill="none"><use href="../assets/icons.svg#icon-chevronSmall"></use></svg> Index</h5></summary><div class="tsd-accordion-details"><section class="tsd-index-section"><h3 class="tsd-index-heading">Properties</h3><div class="tsd-index-list"><a href="SchemaDefinition.html#name" class="tsd-index-link"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="../assets/icons.svg#icon-1024"></use></svg><span>name</span></a>
|
3
|
+
<a href="SchemaDefinition.html#schema" class="tsd-index-link"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="../assets/icons.svg#icon-1024"></use></svg><span>schema</span></a>
|
4
|
+
</div></section></div></details></section></section><section class="tsd-panel-group tsd-member-group"><h2>Properties</h2><section class="tsd-panel tsd-member"><a id="name" class="tsd-anchor"></a><h3 class="tsd-anchor-link"><span>name</span><a href="#name" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h3><div class="tsd-signature"><span class="tsd-kind-property">name</span><span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">string</span></div><div class="tsd-comment tsd-typography"><p>A unique name for the schema to identify which schema matched.</p>
|
5
|
+
</div><div class="tsd-comment tsd-typography"></div><aside class="tsd-sources"><ul><li>Defined in <a href="https://github.com/solvers-hub/llm-json/blob/c66e07bf56dff5952768d1bbe7ca7221c8d2192d/src/types.ts#L26">types.ts:26</a></li></ul></aside></section><section class="tsd-panel tsd-member"><a id="schema" class="tsd-anchor"></a><h3 class="tsd-anchor-link"><span>schema</span><a href="#schema" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h3><div class="tsd-signature"><span class="tsd-kind-property">schema</span><span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">object</span></div><div class="tsd-comment tsd-typography"><p>The JSON schema object conforming to JSON Schema specification.</p>
|
6
|
+
</div><div class="tsd-comment tsd-typography"></div><aside class="tsd-sources"><ul><li>Defined in <a href="https://github.com/solvers-hub/llm-json/blob/c66e07bf56dff5952768d1bbe7ca7221c8d2192d/src/types.ts#L31">types.ts:31</a></li></ul></aside></section></section></div><div class="col-sidebar"><div class="page-menu"><div class="tsd-navigation settings"><details class="tsd-index-accordion"><summary class="tsd-accordion-summary"><h3><svg width="20" height="20" viewBox="0 0 24 24" fill="none"><use href="../assets/icons.svg#icon-chevronDown"></use></svg>Settings</h3></summary><div class="tsd-accordion-details"><div class="tsd-filter-visibility"><h4 class="uppercase">Member Visibility</h4><form><ul id="tsd-filter-options"><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-protected" name="protected"/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>Protected</span></label></li><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-private" name="private"/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>Private</span></label></li><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-inherited" name="inherited" checked/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>Inherited</span></label></li><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-external" name="external"/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>External</span></label></li></ul></form></div><div class="tsd-theme-toggle"><h4 class="uppercase">Theme</h4><select id="tsd-theme"><option value="os">OS</option><option value="light">Light</option><option value="dark">Dark</option></select></div></div></details></div><details open class="tsd-index-accordion tsd-page-navigation"><summary class="tsd-accordion-summary"><h3><svg width="20" height="20" viewBox="0 0 24 24" fill="none"><use href="../assets/icons.svg#icon-chevronDown"></use></svg>On This Page</h3></summary><div class="tsd-accordion-details"><a href="#name" class=""><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="../assets/icons.svg#icon-1024"></use></svg><span>name</span></a><a href="#schema" class=""><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="../assets/icons.svg#icon-1024"></use></svg><span>schema</span></a></div></details></div><div class="site-menu"><nav class="tsd-navigation"><a href="../modules.html"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="../assets/icons.svg#icon-1"></use></svg><span>@solvers-hub/llm-json</span></a><ul class="tsd-small-nested-navigation" id="tsd-nav-container" data-base=".."><li>Loading...</li></ul></nav></div></div></div><footer><p class="tsd-generator">Generated using <a href="https://typedoc.org/" target="_blank">TypeDoc</a></p></footer><div class="overlay"></div></body></html>
|
@@ -0,0 +1,10 @@
|
|
1
|
+
<!DOCTYPE html><html class="default" lang="en"><head><meta charSet="utf-8"/><meta http-equiv="x-ua-compatible" content="IE=edge"/><title>ValidationResult | @solvers-hub/llm-json</title><meta name="description" content="Documentation for @solvers-hub/llm-json"/><meta name="viewport" content="width=device-width, initial-scale=1"/><link rel="stylesheet" href="../assets/style.css"/><link rel="stylesheet" href="../assets/highlight.css"/><script defer src="../assets/main.js"></script><script async src="../assets/icons.js" id="tsd-icons-script"></script><script async src="../assets/search.js" id="tsd-search-script"></script><script async src="../assets/navigation.js" id="tsd-nav-script"></script></head><body><script>document.documentElement.dataset.theme = localStorage.getItem("tsd-theme") || "os";document.body.style.display="none";setTimeout(() => app?app.showPage():document.body.style.removeProperty("display"),500)</script><header class="tsd-page-toolbar"><div class="tsd-toolbar-contents container"><div class="table-cell" id="tsd-search" data-base=".."><div class="field"><label for="tsd-search-field" class="tsd-widget tsd-toolbar-icon search no-caption"><svg width="16" height="16" viewBox="0 0 16 16" fill="none"><use href="../assets/icons.svg#icon-search"></use></svg></label><input type="text" id="tsd-search-field" aria-label="Search"/></div><div class="field"><div id="tsd-toolbar-links"></div></div><ul class="results"><li class="state loading">Preparing search index...</li><li class="state failure">The search index is not available</li></ul><a href="../index.html" class="title">@solvers-hub/llm-json</a></div><div class="table-cell" id="tsd-widgets"><a href="#" class="tsd-widget tsd-toolbar-icon menu no-caption" data-toggle="menu" aria-label="Menu"><svg width="16" height="16" viewBox="0 0 16 16" fill="none"><use href="../assets/icons.svg#icon-menu"></use></svg></a></div></div></header><div class="container container-main"><div class="col-content"><div class="tsd-page-title"><ul class="tsd-breadcrumb"><li><a href="../modules.html">@solvers-hub/llm-json</a></li><li><a href="ValidationResult.html">ValidationResult</a></li></ul><h1>Interface ValidationResult</h1></div><section class="tsd-panel tsd-comment"><div class="tsd-comment tsd-typography"><p>Result of schema validation for a JSON object.</p>
|
2
|
+
</div><div class="tsd-comment tsd-typography"></div></section><div class="tsd-signature"><span class="tsd-signature-keyword">interface </span><span class="tsd-kind-interface">ValidationResult</span> <span class="tsd-signature-symbol">{ </span><br/><span> </span><a class="tsd-kind-property" href="ValidationResult.html#isValid">isValid</a><span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">boolean</span><span class="tsd-signature-symbol">; </span><br/><span> </span><a class="tsd-kind-property" href="ValidationResult.html#json">json</a><span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">any</span><span class="tsd-signature-symbol">; </span><br/><span> </span><a class="tsd-kind-property" href="ValidationResult.html#matchedSchema">matchedSchema</a><span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">null</span><span class="tsd-signature-symbol"> | </span><span class="tsd-signature-type">string</span><span class="tsd-signature-symbol">; </span><br/><span> </span><a class="tsd-kind-property" href="ValidationResult.html#validationErrors">validationErrors</a><span class="tsd-signature-symbol">?: </span><span class="tsd-signature-type">any</span><span class="tsd-signature-symbol">[]</span><span class="tsd-signature-symbol">; </span><br/><span class="tsd-signature-symbol">}</span></div><aside class="tsd-sources"><ul><li>Defined in <a href="https://github.com/solvers-hub/llm-json/blob/c66e07bf56dff5952768d1bbe7ca7221c8d2192d/src/types.ts#L37">types.ts:37</a></li></ul></aside><section class="tsd-panel-group tsd-index-group"><section class="tsd-panel tsd-index-panel"><details class="tsd-index-content tsd-index-accordion" open><summary class="tsd-accordion-summary tsd-index-summary"><h5 class="tsd-index-heading uppercase" role="button" aria-expanded="false" tabIndex="0"><svg width="16" height="16" viewBox="0 0 16 16" fill="none"><use href="../assets/icons.svg#icon-chevronSmall"></use></svg> Index</h5></summary><div class="tsd-accordion-details"><section class="tsd-index-section"><h3 class="tsd-index-heading">Properties</h3><div class="tsd-index-list"><a href="ValidationResult.html#isValid" class="tsd-index-link"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="../assets/icons.svg#icon-1024"></use></svg><span>is<wbr/>Valid</span></a>
|
3
|
+
<a href="ValidationResult.html#json" class="tsd-index-link"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="../assets/icons.svg#icon-1024"></use></svg><span>json</span></a>
|
4
|
+
<a href="ValidationResult.html#matchedSchema" class="tsd-index-link"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="../assets/icons.svg#icon-1024"></use></svg><span>matched<wbr/>Schema</span></a>
|
5
|
+
<a href="ValidationResult.html#validationErrors" class="tsd-index-link"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="../assets/icons.svg#icon-1024"></use></svg><span>validation<wbr/>Errors?</span></a>
|
6
|
+
</div></section></div></details></section></section><section class="tsd-panel-group tsd-member-group"><h2>Properties</h2><section class="tsd-panel tsd-member"><a id="isValid" class="tsd-anchor"></a><h3 class="tsd-anchor-link"><span>is<wbr/>Valid</span><a href="#isValid" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h3><div class="tsd-signature"><span class="tsd-kind-property">is<wbr/>Valid</span><span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">boolean</span></div><div class="tsd-comment tsd-typography"><p>Whether the JSON is valid according to the matched schema.</p>
|
7
|
+
</div><div class="tsd-comment tsd-typography"></div><aside class="tsd-sources"><ul><li>Defined in <a href="https://github.com/solvers-hub/llm-json/blob/c66e07bf56dff5952768d1bbe7ca7221c8d2192d/src/types.ts#L51">types.ts:51</a></li></ul></aside></section><section class="tsd-panel tsd-member"><a id="json" class="tsd-anchor"></a><h3 class="tsd-anchor-link"><span>json</span><a href="#json" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h3><div class="tsd-signature"><span class="tsd-kind-property">json</span><span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">any</span></div><div class="tsd-comment tsd-typography"><p>The JSON object that was validated.</p>
|
8
|
+
</div><div class="tsd-comment tsd-typography"></div><aside class="tsd-sources"><ul><li>Defined in <a href="https://github.com/solvers-hub/llm-json/blob/c66e07bf56dff5952768d1bbe7ca7221c8d2192d/src/types.ts#L41">types.ts:41</a></li></ul></aside></section><section class="tsd-panel tsd-member"><a id="matchedSchema" class="tsd-anchor"></a><h3 class="tsd-anchor-link"><span>matched<wbr/>Schema</span><a href="#matchedSchema" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h3><div class="tsd-signature"><span class="tsd-kind-property">matched<wbr/>Schema</span><span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">null</span><span class="tsd-signature-symbol"> | </span><span class="tsd-signature-type">string</span></div><div class="tsd-comment tsd-typography"><p>The name of the schema that matched, or null if no schema matched.</p>
|
9
|
+
</div><div class="tsd-comment tsd-typography"></div><aside class="tsd-sources"><ul><li>Defined in <a href="https://github.com/solvers-hub/llm-json/blob/c66e07bf56dff5952768d1bbe7ca7221c8d2192d/src/types.ts#L46">types.ts:46</a></li></ul></aside></section><section class="tsd-panel tsd-member"><a id="validationErrors" class="tsd-anchor"></a><h3 class="tsd-anchor-link"><code class="tsd-tag ts-flagOptional">Optional</code> <span>validation<wbr/>Errors</span><a href="#validationErrors" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h3><div class="tsd-signature"><span class="tsd-kind-property">validation<wbr/>Errors</span><span class="tsd-signature-symbol">?:</span> <span class="tsd-signature-type">any</span><span class="tsd-signature-symbol">[]</span></div><div class="tsd-comment tsd-typography"><p>Validation errors if any, or undefined if validation passed.</p>
|
10
|
+
</div><div class="tsd-comment tsd-typography"></div><aside class="tsd-sources"><ul><li>Defined in <a href="https://github.com/solvers-hub/llm-json/blob/c66e07bf56dff5952768d1bbe7ca7221c8d2192d/src/types.ts#L56">types.ts:56</a></li></ul></aside></section></section></div><div class="col-sidebar"><div class="page-menu"><div class="tsd-navigation settings"><details class="tsd-index-accordion"><summary class="tsd-accordion-summary"><h3><svg width="20" height="20" viewBox="0 0 24 24" fill="none"><use href="../assets/icons.svg#icon-chevronDown"></use></svg>Settings</h3></summary><div class="tsd-accordion-details"><div class="tsd-filter-visibility"><h4 class="uppercase">Member Visibility</h4><form><ul id="tsd-filter-options"><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-protected" name="protected"/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>Protected</span></label></li><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-private" name="private"/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>Private</span></label></li><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-inherited" name="inherited" checked/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>Inherited</span></label></li><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-external" name="external"/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>External</span></label></li></ul></form></div><div class="tsd-theme-toggle"><h4 class="uppercase">Theme</h4><select id="tsd-theme"><option value="os">OS</option><option value="light">Light</option><option value="dark">Dark</option></select></div></div></details></div><details open class="tsd-index-accordion tsd-page-navigation"><summary class="tsd-accordion-summary"><h3><svg width="20" height="20" viewBox="0 0 24 24" fill="none"><use href="../assets/icons.svg#icon-chevronDown"></use></svg>On This Page</h3></summary><div class="tsd-accordion-details"><a href="#isValid" class=""><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="../assets/icons.svg#icon-1024"></use></svg><span>is<wbr/>Valid</span></a><a href="#json" class=""><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="../assets/icons.svg#icon-1024"></use></svg><span>json</span></a><a href="#matchedSchema" class=""><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="../assets/icons.svg#icon-1024"></use></svg><span>matched<wbr/>Schema</span></a><a href="#validationErrors" class=""><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="../assets/icons.svg#icon-1024"></use></svg><span>validation<wbr/>Errors</span></a></div></details></div><div class="site-menu"><nav class="tsd-navigation"><a href="../modules.html"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="../assets/icons.svg#icon-1"></use></svg><span>@solvers-hub/llm-json</span></a><ul class="tsd-small-nested-navigation" id="tsd-nav-container" data-base=".."><li>Loading...</li></ul></nav></div></div></div><footer><p class="tsd-generator">Generated using <a href="https://typedoc.org/" target="_blank">TypeDoc</a></p></footer><div class="overlay"></div></body></html>
|
package/docs/modules.html
CHANGED
@@ -4,4 +4,6 @@
|
|
4
4
|
<a href="interfaces/ExtractResult.html" class="tsd-index-link"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="assets/icons.svg#icon-256"></use></svg><span>Extract<wbr/>Result</span></a>
|
5
5
|
<a href="interfaces/JsonBlock.html" class="tsd-index-link"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="assets/icons.svg#icon-256"></use></svg><span>Json<wbr/>Block</span></a>
|
6
6
|
<a href="interfaces/JsonParseError.html" class="tsd-index-link"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="assets/icons.svg#icon-256"></use></svg><span>Json<wbr/>Parse<wbr/>Error</span></a>
|
7
|
+
<a href="interfaces/SchemaDefinition.html" class="tsd-index-link"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="assets/icons.svg#icon-256"></use></svg><span>Schema<wbr/>Definition</span></a>
|
8
|
+
<a href="interfaces/ValidationResult.html" class="tsd-index-link"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="assets/icons.svg#icon-256"></use></svg><span>Validation<wbr/>Result</span></a>
|
7
9
|
</div></section></div></details></section></section><section class="tsd-panel-group tsd-member-group"><h2>References</h2><section class="tsd-panel tsd-member"><a id="default" class="tsd-anchor"></a><h3 class="tsd-anchor-link"><span>default</span><a href="#default" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h3>Renames and re-exports <a href="classes/LlmJson.html">LlmJson</a></section></section></div><div class="col-sidebar"><div class="page-menu"><div class="tsd-navigation settings"><details class="tsd-index-accordion"><summary class="tsd-accordion-summary"><h3><svg width="20" height="20" viewBox="0 0 24 24" fill="none"><use href="assets/icons.svg#icon-chevronDown"></use></svg>Settings</h3></summary><div class="tsd-accordion-details"><div class="tsd-filter-visibility"><h4 class="uppercase">Member Visibility</h4><form><ul id="tsd-filter-options"><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-protected" name="protected"/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>Protected</span></label></li><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-private" name="private"/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>Private</span></label></li><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-inherited" name="inherited" checked/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>Inherited</span></label></li><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-external" name="external"/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>External</span></label></li></ul></form></div><div class="tsd-theme-toggle"><h4 class="uppercase">Theme</h4><select id="tsd-theme"><option value="os">OS</option><option value="light">Light</option><option value="dark">Dark</option></select></div></div></details></div><details open class="tsd-index-accordion tsd-page-navigation"><summary class="tsd-accordion-summary"><h3><svg width="20" height="20" viewBox="0 0 24 24" fill="none"><use href="assets/icons.svg#icon-chevronDown"></use></svg>On This Page</h3></summary><div class="tsd-accordion-details"><a href="#default" class=""><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="assets/icons.svg#icon-4194304"></use></svg><span>default</span></a></div></details></div><div class="site-menu"><nav class="tsd-navigation"><a href="modules.html" class="current"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="assets/icons.svg#icon-1"></use></svg><span>@solvers-hub/llm-json</span></a><ul class="tsd-small-nested-navigation" id="tsd-nav-container" data-base="."><li>Loading...</li></ul></nav></div></div></div><footer><p class="tsd-generator">Generated using <a href="https://typedoc.org/" target="_blank">TypeDoc</a></p></footer><div class="overlay"></div></body></html>
|
package/docs-md/README.md
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
|
5
5
|
A TypeScript SDK for extracting and correcting JSON data from LLM outputs.
|
6
6
|
|
7
|
-
[](https://badge.fury.io/js/llm-json)
|
7
|
+
[](https://badge.fury.io/js/llm-json)
|
8
8
|
[](https://opensource.org/licenses/MIT)
|
9
9
|
|
10
10
|
## Overview
|
@@ -13,47 +13,96 @@ LLM-JSON is a lightweight library designed to parse and extract JSON objects fro
|
|
13
13
|
|
14
14
|
## Key Features
|
15
15
|
|
16
|
-
- **Text/JSON Separation**: Cleanly separates text content from JSON data in LLM outputs
|
17
|
-
- **Multiple JSON Support**: Extracts multiple JSON objects or arrays from a single input
|
18
|
-
- **JSON Validation & Correction**: Automatically fixes common JSON formatting errors from LLMs
|
19
|
-
- **Code Block Support**: Extracts JSON from markdown code blocks (```json)
|
16
|
+
- **Text/JSON Separation**: Cleanly separates text content from JSON data in LLM outputs
|
17
|
+
- **Multiple JSON Support**: Extracts multiple JSON objects or arrays from a single input
|
18
|
+
- **JSON Validation & Correction**: Automatically fixes common JSON formatting errors from LLMs
|
19
|
+
- **Code Block Support**: Extracts JSON from markdown code blocks (```json)
|
20
|
+
- **Schema Validation**: Validates extracted JSON against provided schemas
|
20
21
|
- **TypeScript Support**: Written in TypeScript with full type definitions
|
21
22
|
|
22
23
|
## Quick Start
|
23
24
|
|
24
25
|
### Installation
|
25
26
|
|
26
|
-
```bash
|
27
|
-
npm install llm-json
|
27
|
+
```bash
|
28
|
+
npm install @solvers-hub/llm-json
|
28
29
|
```
|
29
30
|
|
30
31
|
### Basic Usage
|
31
32
|
|
32
|
-
```typescript
|
33
|
-
import { LlmJson } from 'llm-json';
|
33
|
+
```typescript
|
34
|
+
import { LlmJson } from '@solvers-hub/llm-json';
|
34
35
|
|
35
36
|
const llmOutput = `Here's some text followed by JSON:
|
36
37
|
|
37
|
-
{
|
38
|
-
"name": "John",
|
39
|
-
"age": 30,
|
40
|
-
"skills": ["JavaScript", "TypeScript", "React"]
|
38
|
+
{
|
39
|
+
"name": "John",
|
40
|
+
"age": 30,
|
41
|
+
"skills": ["JavaScript", "TypeScript", "React"]
|
41
42
|
}`;
|
42
43
|
|
43
|
-
const llmJson = new LlmJson({ attemptCorrection: true });
|
44
|
+
const llmJson = new LlmJson({ attemptCorrection: true });
|
44
45
|
const { text, json } = llmJson.extract(llmOutput);
|
45
46
|
|
46
|
-
console.log(text); // ['Here\'s some text followed by JSON:']
|
47
|
-
console.log(json); // [{ name: 'John', age: 30, skills: ['JavaScript', 'TypeScript', 'React'] }]
|
47
|
+
console.log(text); // ['Here\'s some text followed by JSON:']
|
48
|
+
console.log(json); // [{ name: 'John', age: 30, skills: ['JavaScript', 'TypeScript', 'React'] }]
|
48
49
|
```
|
49
50
|
|
50
|
-
|
51
|
+
### Schema Validation
|
52
|
+
|
53
|
+
You can validate extracted JSON against schemas:
|
54
|
+
|
55
|
+
```typescript
|
56
|
+
import { LlmJson } from '@solvers-hub/llm-json';
|
57
|
+
|
58
|
+
const schemas = [
|
59
|
+
{
|
60
|
+
name: 'person',
|
61
|
+
schema: {
|
62
|
+
type: 'object',
|
63
|
+
properties: {
|
64
|
+
name: { type: 'string' },
|
65
|
+
age: { type: 'integer' }
|
66
|
+
},
|
67
|
+
required: ['name', 'age']
|
68
|
+
}
|
69
|
+
}
|
70
|
+
];
|
71
|
+
|
72
|
+
const llmJson = new LlmJson({
|
73
|
+
attemptCorrection: true,
|
74
|
+
schemas
|
75
|
+
});
|
76
|
+
|
77
|
+
const llmOutput = `Here's a person: {"name": "John", "age": 30}
|
78
|
+
And some other data: {"title": "Meeting notes"}`;
|
79
|
+
const result = llmJson.extract(llmOutput);
|
80
|
+
|
81
|
+
// Note: All extracted JSON objects are included in the json array
|
82
|
+
console.log(result.json);
|
83
|
+
// [
|
84
|
+
// { name: 'John', age: 30 },
|
85
|
+
// { title: 'Meeting notes' }
|
86
|
+
// ]
|
87
|
+
|
88
|
+
// The validatedJson array includes validation results for each JSON object
|
89
|
+
console.log(result.validatedJson);
|
90
|
+
// [
|
91
|
+
// {
|
92
|
+
// json: { name: 'John', age: 30 },
|
93
|
+
// matchedSchema: 'person',
|
94
|
+
// isValid: true
|
95
|
+
// },
|
96
|
+
// {
|
97
|
+
// json: { title: 'Meeting notes' },
|
98
|
+
// matchedSchema: null,
|
99
|
+
// isValid: false,
|
100
|
+
// validationErrors: [...] // Validation errors
|
101
|
+
// }
|
102
|
+
// ]
|
51
103
|
|
52
|
-
|
53
|
-
|
54
|
-
- [API Documentation](./docs/README.md)
|
55
|
-
- [Examples](./docs/examples.md)
|
104
|
+
```
|
56
105
|
|
57
106
|
## License
|
58
107
|
|
59
|
-
MIT ©
|
108
|
+
MIT © 2025
|
@@ -42,7 +42,7 @@ Creates a new LlmJson instance with the specified options.
|
|
42
42
|
|
43
43
|
#### Defined in
|
44
44
|
|
45
|
-
[index.ts:17](https://github.com/solvers-hub/llm-json/blob/
|
45
|
+
[index.ts:17](https://github.com/solvers-hub/llm-json/blob/6d8d00890ee1d42b63f8bb8c3f6401333e41041e/src/index.ts#L17)
|
46
46
|
|
47
47
|
## Properties
|
48
48
|
|
@@ -52,7 +52,7 @@ Creates a new LlmJson instance with the specified options.
|
|
52
52
|
|
53
53
|
#### Defined in
|
54
54
|
|
55
|
-
[index.ts:11](https://github.com/solvers-hub/llm-json/blob/
|
55
|
+
[index.ts:11](https://github.com/solvers-hub/llm-json/blob/6d8d00890ee1d42b63f8bb8c3f6401333e41041e/src/index.ts#L11)
|
56
56
|
|
57
57
|
___
|
58
58
|
|
@@ -62,7 +62,7 @@ ___
|
|
62
62
|
|
63
63
|
#### Defined in
|
64
64
|
|
65
|
-
[index.ts:10](https://github.com/solvers-hub/llm-json/blob/
|
65
|
+
[index.ts:10](https://github.com/solvers-hub/llm-json/blob/6d8d00890ee1d42b63f8bb8c3f6401333e41041e/src/index.ts#L10)
|
66
66
|
|
67
67
|
___
|
68
68
|
|
@@ -72,7 +72,7 @@ ___
|
|
72
72
|
|
73
73
|
#### Defined in
|
74
74
|
|
75
|
-
[index.ts:9](https://github.com/solvers-hub/llm-json/blob/
|
75
|
+
[index.ts:9](https://github.com/solvers-hub/llm-json/blob/6d8d00890ee1d42b63f8bb8c3f6401333e41041e/src/index.ts#L9)
|
76
76
|
|
77
77
|
## Methods
|
78
78
|
|
@@ -96,7 +96,7 @@ An object containing arrays of extracted text and JSON.
|
|
96
96
|
|
97
97
|
#### Defined in
|
98
98
|
|
99
|
-
[index.ts:39](https://github.com/solvers-hub/llm-json/blob/
|
99
|
+
[index.ts:39](https://github.com/solvers-hub/llm-json/blob/6d8d00890ee1d42b63f8bb8c3f6401333e41041e/src/index.ts#L39)
|
100
100
|
|
101
101
|
___
|
102
102
|
|
@@ -120,7 +120,7 @@ An object containing arrays of extracted text and JSON.
|
|
120
120
|
|
121
121
|
#### Defined in
|
122
122
|
|
123
|
-
[index.ts:48](https://github.com/solvers-hub/llm-json/blob/
|
123
|
+
[index.ts:48](https://github.com/solvers-hub/llm-json/blob/6d8d00890ee1d42b63f8bb8c3f6401333e41041e/src/index.ts#L48)
|
124
124
|
|
125
125
|
___
|
126
126
|
|
@@ -144,4 +144,4 @@ The LlmJson singleton instance.
|
|
144
144
|
|
145
145
|
#### Defined in
|
146
146
|
|
147
|
-
[index.ts:27](https://github.com/solvers-hub/llm-json/blob/
|
147
|
+
[index.ts:27](https://github.com/solvers-hub/llm-json/blob/6d8d00890ee1d42b63f8bb8c3f6401333e41041e/src/index.ts#L27)
|
@@ -9,6 +9,7 @@ Options for JSON extraction.
|
|
9
9
|
### Properties
|
10
10
|
|
11
11
|
- [attemptCorrection](ExtractOptions.md#attemptcorrection)
|
12
|
+
- [schemas](ExtractOptions.md#schemas)
|
12
13
|
|
13
14
|
## Properties
|
14
15
|
|
@@ -26,4 +27,23 @@ false
|
|
26
27
|
|
27
28
|
#### Defined in
|
28
29
|
|
29
|
-
[types.ts:9](https://github.com/solvers-hub/llm-json/blob/
|
30
|
+
[types.ts:9](https://github.com/solvers-hub/llm-json/blob/6d8d00890ee1d42b63f8bb8c3f6401333e41041e/src/types.ts#L9)
|
31
|
+
|
32
|
+
___
|
33
|
+
|
34
|
+
### schemas
|
35
|
+
|
36
|
+
• `Optional` **schemas**: [`SchemaDefinition`](SchemaDefinition.md)[]
|
37
|
+
|
38
|
+
JSON schemas to validate extracted JSON against.
|
39
|
+
If provided, the extracted JSON will be validated against these schemas.
|
40
|
+
|
41
|
+
**`Default`**
|
42
|
+
|
43
|
+
```ts
|
44
|
+
undefined
|
45
|
+
```
|
46
|
+
|
47
|
+
#### Defined in
|
48
|
+
|
49
|
+
[types.ts:16](https://github.com/solvers-hub/llm-json/blob/6d8d00890ee1d42b63f8bb8c3f6401333e41041e/src/types.ts#L16)
|
@@ -10,6 +10,7 @@ Result of the JSON extraction.
|
|
10
10
|
|
11
11
|
- [json](ExtractResult.md#json)
|
12
12
|
- [text](ExtractResult.md#text)
|
13
|
+
- [validatedJson](ExtractResult.md#validatedjson)
|
13
14
|
|
14
15
|
## Properties
|
15
16
|
|
@@ -21,7 +22,7 @@ Array of parsed JSON objects extracted from the input.
|
|
21
22
|
|
22
23
|
#### Defined in
|
23
24
|
|
24
|
-
[types.ts:
|
25
|
+
[types.ts:71](https://github.com/solvers-hub/llm-json/blob/6d8d00890ee1d42b63f8bb8c3f6401333e41041e/src/types.ts#L71)
|
25
26
|
|
26
27
|
___
|
27
28
|
|
@@ -33,4 +34,16 @@ Array of text blocks extracted from the input.
|
|
33
34
|
|
34
35
|
#### Defined in
|
35
36
|
|
36
|
-
[types.ts:
|
37
|
+
[types.ts:66](https://github.com/solvers-hub/llm-json/blob/6d8d00890ee1d42b63f8bb8c3f6401333e41041e/src/types.ts#L66)
|
38
|
+
|
39
|
+
___
|
40
|
+
|
41
|
+
### validatedJson
|
42
|
+
|
43
|
+
• `Optional` **validatedJson**: [`ValidationResult`](ValidationResult.md)[]
|
44
|
+
|
45
|
+
Array of validated JSON results, only present if schemas were provided.
|
46
|
+
|
47
|
+
#### Defined in
|
48
|
+
|
49
|
+
[types.ts:76](https://github.com/solvers-hub/llm-json/blob/6d8d00890ee1d42b63f8bb8c3f6401333e41041e/src/types.ts#L76)
|
@@ -24,7 +24,7 @@ The end index of the JSON block in the input string.
|
|
24
24
|
|
25
25
|
#### Defined in
|
26
26
|
|
27
|
-
[types.ts:
|
27
|
+
[types.ts:96](https://github.com/solvers-hub/llm-json/blob/6d8d00890ee1d42b63f8bb8c3f6401333e41041e/src/types.ts#L96)
|
28
28
|
|
29
29
|
___
|
30
30
|
|
@@ -36,7 +36,7 @@ The parsed JSON object.
|
|
36
36
|
|
37
37
|
#### Defined in
|
38
38
|
|
39
|
-
[types.ts:
|
39
|
+
[types.ts:106](https://github.com/solvers-hub/llm-json/blob/6d8d00890ee1d42b63f8bb8c3f6401333e41041e/src/types.ts#L106)
|
40
40
|
|
41
41
|
___
|
42
42
|
|
@@ -48,7 +48,7 @@ The raw JSON string.
|
|
48
48
|
|
49
49
|
#### Defined in
|
50
50
|
|
51
|
-
[types.ts:
|
51
|
+
[types.ts:86](https://github.com/solvers-hub/llm-json/blob/6d8d00890ee1d42b63f8bb8c3f6401333e41041e/src/types.ts#L86)
|
52
52
|
|
53
53
|
___
|
54
54
|
|
@@ -60,7 +60,7 @@ The start index of the JSON block in the input string.
|
|
60
60
|
|
61
61
|
#### Defined in
|
62
62
|
|
63
|
-
[types.ts:
|
63
|
+
[types.ts:91](https://github.com/solvers-hub/llm-json/blob/6d8d00890ee1d42b63f8bb8c3f6401333e41041e/src/types.ts#L91)
|
64
64
|
|
65
65
|
___
|
66
66
|
|
@@ -72,4 +72,4 @@ Whether the JSON was corrected.
|
|
72
72
|
|
73
73
|
#### Defined in
|
74
74
|
|
75
|
-
[types.ts:
|
75
|
+
[types.ts:101](https://github.com/solvers-hub/llm-json/blob/6d8d00890ee1d42b63f8bb8c3f6401333e41041e/src/types.ts#L101)
|
@@ -22,7 +22,7 @@ The original error message.
|
|
22
22
|
|
23
23
|
#### Defined in
|
24
24
|
|
25
|
-
[types.ts:
|
25
|
+
[types.ts:116](https://github.com/solvers-hub/llm-json/blob/6d8d00890ee1d42b63f8bb8c3f6401333e41041e/src/types.ts#L116)
|
26
26
|
|
27
27
|
___
|
28
28
|
|
@@ -34,7 +34,7 @@ The position in the JSON string where the error occurred.
|
|
34
34
|
|
35
35
|
#### Defined in
|
36
36
|
|
37
|
-
[types.ts:
|
37
|
+
[types.ts:126](https://github.com/solvers-hub/llm-json/blob/6d8d00890ee1d42b63f8bb8c3f6401333e41041e/src/types.ts#L126)
|
38
38
|
|
39
39
|
___
|
40
40
|
|
@@ -46,4 +46,4 @@ The raw JSON string that failed to parse.
|
|
46
46
|
|
47
47
|
#### Defined in
|
48
48
|
|
49
|
-
[types.ts:
|
49
|
+
[types.ts:121](https://github.com/solvers-hub/llm-json/blob/6d8d00890ee1d42b63f8bb8c3f6401333e41041e/src/types.ts#L121)
|
@@ -0,0 +1,36 @@
|
|
1
|
+
[@solvers-hub/llm-json](../README.md) / [Exports](../modules.md) / SchemaDefinition
|
2
|
+
|
3
|
+
# Interface: SchemaDefinition
|
4
|
+
|
5
|
+
Definition of a JSON schema for validation.
|
6
|
+
|
7
|
+
## Table of contents
|
8
|
+
|
9
|
+
### Properties
|
10
|
+
|
11
|
+
- [name](SchemaDefinition.md#name)
|
12
|
+
- [schema](SchemaDefinition.md#schema)
|
13
|
+
|
14
|
+
## Properties
|
15
|
+
|
16
|
+
### name
|
17
|
+
|
18
|
+
• **name**: `string`
|
19
|
+
|
20
|
+
A unique name for the schema to identify which schema matched.
|
21
|
+
|
22
|
+
#### Defined in
|
23
|
+
|
24
|
+
[types.ts:26](https://github.com/solvers-hub/llm-json/blob/6d8d00890ee1d42b63f8bb8c3f6401333e41041e/src/types.ts#L26)
|
25
|
+
|
26
|
+
___
|
27
|
+
|
28
|
+
### schema
|
29
|
+
|
30
|
+
• **schema**: `object`
|
31
|
+
|
32
|
+
The JSON schema object conforming to JSON Schema specification.
|
33
|
+
|
34
|
+
#### Defined in
|
35
|
+
|
36
|
+
[types.ts:31](https://github.com/solvers-hub/llm-json/blob/6d8d00890ee1d42b63f8bb8c3f6401333e41041e/src/types.ts#L31)
|
@@ -0,0 +1,62 @@
|
|
1
|
+
[@solvers-hub/llm-json](../README.md) / [Exports](../modules.md) / ValidationResult
|
2
|
+
|
3
|
+
# Interface: ValidationResult
|
4
|
+
|
5
|
+
Result of schema validation for a JSON object.
|
6
|
+
|
7
|
+
## Table of contents
|
8
|
+
|
9
|
+
### Properties
|
10
|
+
|
11
|
+
- [isValid](ValidationResult.md#isvalid)
|
12
|
+
- [json](ValidationResult.md#json)
|
13
|
+
- [matchedSchema](ValidationResult.md#matchedschema)
|
14
|
+
- [validationErrors](ValidationResult.md#validationerrors)
|
15
|
+
|
16
|
+
## Properties
|
17
|
+
|
18
|
+
### isValid
|
19
|
+
|
20
|
+
• **isValid**: `boolean`
|
21
|
+
|
22
|
+
Whether the JSON is valid according to the matched schema.
|
23
|
+
|
24
|
+
#### Defined in
|
25
|
+
|
26
|
+
[types.ts:51](https://github.com/solvers-hub/llm-json/blob/6d8d00890ee1d42b63f8bb8c3f6401333e41041e/src/types.ts#L51)
|
27
|
+
|
28
|
+
___
|
29
|
+
|
30
|
+
### json
|
31
|
+
|
32
|
+
• **json**: `any`
|
33
|
+
|
34
|
+
The JSON object that was validated.
|
35
|
+
|
36
|
+
#### Defined in
|
37
|
+
|
38
|
+
[types.ts:41](https://github.com/solvers-hub/llm-json/blob/6d8d00890ee1d42b63f8bb8c3f6401333e41041e/src/types.ts#L41)
|
39
|
+
|
40
|
+
___
|
41
|
+
|
42
|
+
### matchedSchema
|
43
|
+
|
44
|
+
• **matchedSchema**: ``null`` \| `string`
|
45
|
+
|
46
|
+
The name of the schema that matched, or null if no schema matched.
|
47
|
+
|
48
|
+
#### Defined in
|
49
|
+
|
50
|
+
[types.ts:46](https://github.com/solvers-hub/llm-json/blob/6d8d00890ee1d42b63f8bb8c3f6401333e41041e/src/types.ts#L46)
|
51
|
+
|
52
|
+
___
|
53
|
+
|
54
|
+
### validationErrors
|
55
|
+
|
56
|
+
• `Optional` **validationErrors**: `any`[]
|
57
|
+
|
58
|
+
Validation errors if any, or undefined if validation passed.
|
59
|
+
|
60
|
+
#### Defined in
|
61
|
+
|
62
|
+
[types.ts:56](https://github.com/solvers-hub/llm-json/blob/6d8d00890ee1d42b63f8bb8c3f6401333e41041e/src/types.ts#L56)
|
package/docs-md/modules.md
CHANGED
@@ -18,6 +18,8 @@
|
|
18
18
|
- [ExtractResult](interfaces/ExtractResult.md)
|
19
19
|
- [JsonBlock](interfaces/JsonBlock.md)
|
20
20
|
- [JsonParseError](interfaces/JsonParseError.md)
|
21
|
+
- [SchemaDefinition](interfaces/SchemaDefinition.md)
|
22
|
+
- [ValidationResult](interfaces/ValidationResult.md)
|
21
23
|
|
22
24
|
## References
|
23
25
|
|