Agent skill

Corvus Typed Model Construction

by corvus-dotnet in corvus-dotnet/Corvus.JsonSchema

Construct instances of generated Corvus strongly-typed models (DTOs, request/response bodies, discriminated-union variants) allocation-free, without composing or parsing JSON.

Apache-2.0Auto-check passedAI & LLM Engineering

Install Corvus Typed Model Construction

skills CLI
$ npx skills add corvus-dotnet/Corvus.JsonSchema --skill corvus-typed-model-construction -a claude-code

Project install by default; add -g for ~/.claude/skills/.

GitHub CLI
$ gh skill install corvus-dotnet/Corvus.JsonSchema corvus-typed-model-construction --agent claude-code

Project scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).

Manual copy
$ git clone --depth 1 https://github.com/corvus-dotnet/Corvus.JsonSchema.git skills-src && mkdir -p .claude/skills && cp -r skills-src/.github/skills/corvus-typed-model-construction .claude/skills/corvus-typed-model-construction && rm -rf skills-src

Use ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.

Claude Code skills documentation · loads skills from .claude/skills/

Facts

Skill name
corvus-typed-model-construction
GitHub stars
199
Token cost
~2.4k tokens
SKILL.md length
839 words
Files
1
Skills in repo
28
Repo updated
First seen
Licence
Apache-2.0

At a glance

Construct instances of generated Corvus strongly-typed models (DTOs, request/response bodies, discriminated-union variants) allocation-free, without composing or parsing JSON.

  • : building a generated model from native values to pass to a generated client/handler
  • SKILL.md covers Never compose-then-parse, The factories — pick by…, The ref-safety trap (the one… and Discriminated unions (oneOf), plus 3 more sections
  • Instructions only: no scripts, shell commands, URLs or credentials in SKILL.md
  • Embedding a JsonElement/array value into a generated object

What it does

Corvus Typed Model Construction is an agent skill from corvus-dotnet/Corvus.JsonSchema. Construct instances of generated Corvus strongly-typed models (DTOs, request/response bodies, discriminated-union variants) allocation-free, without composing or parsing JSON. Covers the Create() / Build() / CreateBuilder() / CreateBuilder<TContext() factories, threading state through a context tuple with STATIC lambdas to avoid closures, the JsonElement.Source ref-safety trap and its fix, avoiding interim materializations, and building discriminated-union bodies. USE FOR: building a generated model from native…

Its SKILL.md is about 2.4k tokens, which your agent loads only when the skill is triggered. It is a single SKILL.md file with no bundled scripts.

It sits in AI & LLM Engineering, covering Embeddings. The repository describes itself as: Support for Json Schema validation and entity generation. The licence is Apache-2.0.

When your agent uses it

  • : building a generated model from native values to pass to a generated client/handler
  • Embedding a JsonElement/array value into a generated object
  • Building union variants
  • Fixing CS8168/CS8347/CS8350 around builders

Example prompts

  • “/corvus-typed-model-construction”

What it can do on your machine

Read from SKILL.md and the folder at commit 973097f. It shows what the files ask for, not the result of running them.

  • Tool permissions

    Pre-approves nothing: there is no allowed-tools line, so your agent's usual permission prompts apply.

    From allowed-tools in the SKILL.md frontmatter.

  • Runs code

    No scripts in the folder and no shell commands in SKILL.md (its code samples are csharp).

    From the folder's file list and the shell code blocks in SKILL.md.

  • Network

    No URLs in SKILL.md.

    From URLs in SKILL.md, links to its own repository left out.

  • Credentials

    Names no API keys, tokens, secrets or passwords.

    From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.

Context cost

Corvus Typed Model Construction loads about 2.4k tokens when it runs. Until then it costs about 234 tokens; SKILL.md has 839 words of instructions outside code blocks.

Always · name and description, kept in context so the agent knows when to use it
~234
When it runs · the whole SKILL.md, loaded when a task matches
~2.4k

Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.

Safety

Auto-check passed

The automated check found no risky patterns in SKILL.md.

Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); files beside SKILL.md are not scanned.

SKILL.md

The full file from corvus-dotnet/Corvus.JsonSchema at commit 973097f, republished under its Apache-2.0 licence (© corvus-dotnet). 839 words, ~2,440 tokens.

Download SKILL.mdSave it as .claude/skills/corvus-typed-model-construction/SKILL.md (or your agent's skills folder).
name
corvus-typed-model-construction
description
Construct instances of generated Corvus strongly-typed models (DTOs, request/response bodies, discriminated-union variants) allocation-free, without composing or parsing JSON. Covers the Create() / Build() / CreateBuilder() / CreateBuilder<TContext>() factories, threading state through a context tuple with STATIC lambdas to avoid closures, the JsonElement.Source ref-safety trap and its fix, avoiding interim materializations, and building discriminated-union bodies. USE FOR: building a generated model from native values to pass to a generated client/handler, embedding a JsonElement/array value into a generated object, building union variants, fixing CS8168/CS8347/CS8350 around builders. DO NOT USE FOR: mutating an arbitrary JsonElement document (use corvus-mutable-documents), read-only parsing (use corvus-parsed-documents-and-memory), ref-struct callback signatures (use ref-struct-delegates).

Typed Model Construction (allocation-free)

Generated Corvus types ([JsonSchemaTypeGenerator] / openapi-client / openapi-server models) are built through value-typed factories that write once into a pooled arena. The goal is to go from native values (int, string, a JsonElement) straight into the model with no interim string/JSON, no ParseValue, and no closure allocation.

Never compose-then-parse

csharp
// ❌ interim string + parse + re-validate. Do not build request/response bodies this way.
var body = $$"""{"mode":"Rewind","targetCursor":{{n}}}""";
Models.ResumeRequest req = JsonElement.ParseValue(body);

Use the generated factories instead.

The factories — pick by situation

FactoryReturnsUse when
T.Build(field: v, …)T.Source (lazy)The default. Native values — including a JsonElement/array — passed straight in. Hand the Source to a consumer that materializes it once (a generated client/handler method). No workspace, no closure.
T.Build(static (ref T.Builder b) => b.Create(…))T.Source (lazy)No fields to set (e.g. a const-only union variant), or you need imperative logic. Lambda MUST be static.
T.CreateBuilder(ws, field: v, …) then .RootElementT (immutable, in ws)Only when you actually need a materialized value (e.g. to read it back, or store it). Not needed just to pass to a consumer.
T.CreateBuilder<TContext>(ws, ctx, static (in TContext ctx, ref T.Builder b) => …) then .RootElementTMaterializing while threading runtime values into a builder loop/conditional. The form the JMESPath/Jsonata/OpenApi generators emit.
T.CreateBuilder<TContext>(ws, in T.Source<TContext> body) then .RootElementTMaterializing a body you already assembled closure-free as a Source<TContext>. Usually you don't call this directly — the generated …Result.Ok<TContext>(T.Source<TContext> body, ws) does, in a single pass. See corvus-builder-context-threading.

Default to T.Build(field: v, …) — it is lazy and the consumer materializes it directly into its own buffer (one pass, no interim document). You almost never need CreateBuilder + .RootElement; reach for it only when you genuinely need a materialized value in hand.

Reaching a server result factory closure-free: build the body as a context-threaded T.Source<TContext> (T.Build<TContext>(in ctx, …), the context a RefTuple) and hand it to the generic …Result.Ok<TContext>(body, ws) overload — one closure-free materialization. Do not CreateBuilder<TContext>(…).RootElement then pass the immutable to the non-generic Ok (that re-materializes). Full detail: corvus-builder-context-threading.

csharp
// ✅ lazy, no workspace, no materialization — pass the builder straight to the client
await client.ResumeRunAsync(runId, RewindResume.Build(targetCursor), ct);                 // int
await client.CancelRunAsync(runId, CancelRequest.Build(reason), ct);                       // string
using var doc = ParsedJsonDocument<JsonElement>.Parse(File.ReadAllBytes(path));
await client.ResumeRunAsync(runId, SkipResume.Build(skipOutputs: doc.RootElement), ct);    // JsonElement, passed directly

Don't hand-roll the Source constructor when Build covers it. A plain field set is T.Build(field: v, …). Reach for the raw new T.Source((ref T.Builder b) => b.Create(…)) constructor only for genuine imperative logic — not to set a couple of fields. (Older code in the tree uses the constructor form for simple bodies; prefer Build.)

csharp
// ❌ hand-rolled constructor for a plain field set
var body = new Models.MemberWrite.Source((ref Models.MemberWrite.Builder b) => b.Create(value: v, dimension: d));
// ✅ the Build factory
var body = Models.MemberWrite.Build(value: v, dimension: d);

Build takes its fields by in, so consume its result in place — don't return it from a helper. Because Build(in field, …) holds a ref to each argument, its Source cannot escape the method that built it: pass it directly to the consumer in the same expression (the common case). Wrapping Build in a method that returns the Source fails with CS8347 / CS8156 ("may expose variables … outside their declaration scope" / "cannot be … returned by reference"). If you want a named local, build and consume it in the same scope.

csharp
// ✅ consumed in place
await client.AddAdministratorAsync(baseId, Models.MemberWrite.Build(value: v, dimension: d), ct);

// ❌ returning Build's result escapes the in-ref (CS8347/CS8156)
static Models.MemberWrite.Source Member(string d, string v) => Models.MemberWrite.Build(value: v, dimension: d);
Show full SKILL.md (394 more words)Show less

The ref-safety trap (the one real gotcha)

JsonElement.Source is a ref struct created from in JsonElement — it holds a ref to the element. Passing a JsonElement directly as an argument to a Build(in …)/CreateBuilder(in …) factory is fine (the factory call's scope keeps the source document alive). What fails is capturing a JsonElement in a (non-static) builder lambda — the captured ref escapes into the closure and the compiler rejects it:

csharp
// ❌ CS8168 / CS8347 / CS8350 — outputs is captured; its ref escapes the closure
JsonElement outputs = doc.RootElement;
var src = new SkipResume.Source((ref SkipResume.Builder b) => b.Create(skipOutputs: outputs));

// ✅ pass it to the native-field factory instead — no lambda, no capture
var src = SkipResume.Build(skipOutputs: doc.RootElement);

If you genuinely need imperative building and a threaded JsonElement, use the TContext form so the value flows through scoped in rather than a closure:

csharp
var value = T.CreateBuilder(
    workspace,
    (src: someElement, ws: workspace),
    static (in (JsonElement src, JsonWorkspace ws) ctx, ref T.Builder b) => { /* use ctx.src */ }).RootElement;

Always make builder lambdas static and thread state via the context tuple — a non-static lambda allocates a closure and reintroduces the capture/escape problem.

Discriminated unions (oneOf)

Build the variant, not the union; the variant Source implicitly converts to the union's (non-generic) Source, so you pass the builder straight to the consumer — no materialization:

csharp
// RewindResume.Source / StatePatchResume.Source  -->  ResumeRequest.Source (implicit) --> client
await client.ResumeRunAsync(runId, RewindResume.Build(targetCursor), ct);
await client.ResumeRunAsync(runId, StatePatchResume.Build(patchArray), ct);

const-discriminated variants set their own discriminator inside Build/Create, so you never set mode (etc.) yourself.

Caveat (rare): a variant's Source<TContext> does NOT implicitly convert to the union's non-generic Source. So if you must use the TContext threading form for a union body, materialize that variant via CreateBuilder<TContext>(ws, …).RootElement and pass the immutable (which converts via the Source(Variant instance) operator). The native-field Build(field: v) factory avoids this entirely, so prefer it.

Lifetime

The immutable returned by .RootElement is a view over the workspace (and .Source lazies reference whatever they were built from). Keep the JsonWorkspace / source ParsedJsonDocument alive until the consumer has finished writing the value (e.g. across the await on a client call). All of JsonWorkspace, JsonDocumentBuilder<T>, ParsedJsonDocument<T> are using-disposable.

Conversions cheat-sheet

  • string → JsonString.Source, int → JsonInt32.Source, int/long → JsonInteger/Schema.Source, DateTimeOffset/ISO string → JsonDateTime.Source — all implicit.
  • JsonElement → JsonElement.Source (implicit, by-ref — the trap above).
  • A generated value T → its containing union's Source (implicit). Chained two-hop user conversions are NOT allowed at an argument — introduce an intermediate local for the first hop.

Cross-References

  • corvus-builder-context-threading — building from UTF-8 spans in a loop with no closure (the Build<TContext> / CreateBuilder<TContext> form and its ref-safety gotchas); reach for it when the values are spans, not native string/int.
  • corvus-bytes-to-bytes — when to thread spans at all (the record<->document string-seam anti-pattern + the genuine-leaf proof).
  • corvus-mutable-documents — JsonWorkspace / JsonDocumentBuilder and mutating arbitrary JsonElement documents.
  • ref-struct-delegates — why builder callbacks use named Build delegates (ref struct params) not Func<>/Action<>.
  • corvus-buffer-and-pooling — the pooling that backs the workspace arena.
  • corvus-codegen — how these factories are generated.

© corvus-dotnet, Apache-2.0. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file

Files

Just SKILL.md in .github/skills/corvus-typed-model-construction of corvus-dotnet/Corvus.JsonSchema.

Open the folder on GitHubat commit 973097f

Compare with similar skills

Corvus Typed Model Construction next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.

Corvus Typed Model Construction compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
Corvus Typed Model Construction this skillcorvus-dotnet/Corvus.JsonSchema199—~2.4kAutomated safety check: PassApache-2.0
Chroma Vector DatabaseOrchestra-Research/AI-Research-SKILLs13k7 repos~2.3kAutomated safety check: PassMIT
SageMaker Serving Image Selectionhuggingface/skills11k1 repos~4.6kAutomated safety check: PassApache-2.0
Codebase Managementgiancarloerra/SocratiCode3.3k1 repos~1.8kAutomated safety check: PassAGPL-3.0
CLIP Image-Text MatchingOrchestra-Research/AI-Research-SKILLs13k7 repos~1.7kAutomated safety check: PassMIT
Sentence-Transformers Training Routerhuggingface/skills11k1 repos~2.6kAutomated safety check: PassApache-2.0

Similar skills

  • Chroma Vector Database

    Orchestra-Research/AI-Research-SKILLs

    Shows how to store documents and embeddings in Chroma, query them by similarity with metadata filters, and persist them to disk for RAG and semantic search projects.

    13k GitHub starsUsed in 7 repos~2.3k tokens
    AI & LLM EngineeringAuto-check passed
  • Official

    Chooses the right serving container and current image URI for deploying a Hugging Face model to a SageMaker endpoint, preferring Hugging Face images over generic ones.

    11k GitHub starsUsed in 1 repo~4.6k tokens
    AI & LLM EngineeringAuto-check passed
  • Codebase Management

    giancarloerra/SocratiCode

    Set up, index, and manage SocratiCode codebase indexing. An agent skill from giancarloerra/SocratiCode.

    3.3k GitHub starsUsed in 1 repo~1.8k tokens
    AI & LLM EngineeringAuto-check passed
  • CLIP Image-Text Matching

    Orchestra-Research/AI-Research-SKILLs

    Explains OpenAI's CLIP model for zero-shot image classification, image-text similarity, semantic image search and content moderation, with install steps and code patterns.

    13k GitHub starsUsed in 7 repos~1.7k tokens
    AI & LLM EngineeringAuto-check passed
  • Official

    Routes a sentence-transformers training task to the right model type and required reference docs and example scripts, covering bi-encoders, rerankers, sparse and multi-vector models.

    11k GitHub starsUsed in 1 repo~2.6k tokens
    AI & LLM EngineeringAuto-check passed
  • Mashup Mods

    rehan-remade/universal-modder

    Build cross-game mashups and total conversions, the "Minecraft inside Elden Ring" or "skateboarding in MW2" kind.

    5.8k GitHub stars~3.3k tokensUpdated today
    AI & LLM EngineeringAuto-check passed

More from corvus-dotnet/Corvus.JsonSchema

All 28 skills in this repo
  • Corvus Analyzers

    corvus-dotnet/Corvus.JsonSchema

    Understand and work with the Roslyn analyzers shipped with Corvus.Text.Json.

    199 GitHub stars~876 tokensUpdated today
    Auto-check passed
  • Corvus Benchmarks

    corvus-dotnet/Corvus.JsonSchema

    Run, interpret, and maintain BenchmarkDotNet benchmarks for JSON Schema validation and query languages.

    199 GitHub stars~1.2k tokensUpdated today
    Auto-check passed
  • Corvus Bowtie Testing

    corvus-dotnet/Corvus.JsonSchema

    Test Corvus.JsonSchema against the JSON Schema Test Suite using Bowtie, the cross-implementation meta-validator.

    199 GitHub stars~1.4k tokensUpdated today
    Auto-check passed
  • Corvus Buffer And Pooling

    corvus-dotnet/Corvus.JsonSchema

    Write allocation-efficient buffer code in Corvus.JsonSchema using the codebase's established three-tier pooling pattern: stackalloc → ArrayPool → ThreadStatic caches.

    199 GitHub stars~2.9k tokensUpdated today
    Auto-check passed
  • Corvus Bytes To Bytes

    corvus-dotnet/Corvus.JsonSchema

    Eliminate hand-rolled POCO record<-document string seams — types/paths that materialize a managed string (or List<string/Dictionary) between a bytes SOURCE (a parsed UTF-8 body, a DB column, a…

    199 GitHub stars~3k tokensUpdated today
    Auto-check passed
  • Corvus Codegen

    corvus-dotnet/Corvus.JsonSchema

    Generate strongly-typed C from JSON Schema using the Roslyn source generator or the corvusjson CLI tool.

    199 GitHub stars~2.1k tokensUpdated today
    Auto-check passed

Questions about Corvus Typed Model Construction

What does Corvus Typed Model Construction do?

Construct instances of generated Corvus strongly-typed models (DTOs, request/response bodies, discriminated-union variants) allocation-free, without composing or parsing JSON. JsonSchema. Construct instances of generated Corvus strongly-typed models (DTOs, request/response bodies, discriminated-union variants) allocation-free, without composing or parsing JSON.

When should I use Corvus Typed Model Construction?

Corvus Typed Model Construction fits situations like: : building a generated model from native values to pass to a generated client/handler; embedding a JsonElement/array value into a generated object; building union variants; fixing CS8168/CS8347/CS8350 around builders.

How do I install Corvus Typed Model Construction in Claude Code?

Run `npx skills add corvus-dotnet/Corvus.JsonSchema --skill corvus-typed-model-construction -a claude-code`. Or copy the skill folder (.github/skills/corvus-typed-model-construction in corvus-dotnet/Corvus.JsonSchema) into .claude/skills/corvus-typed-model-construction in your project. Claude Code loads it when a task matches its description.

How do I install Corvus Typed Model Construction in Codex?

Run `npx skills add corvus-dotnet/Corvus.JsonSchema --skill corvus-typed-model-construction -a codex`. Or copy the skill folder (.github/skills/corvus-typed-model-construction in corvus-dotnet/Corvus.JsonSchema) into .agents/skills/corvus-typed-model-construction in your project. Codex loads it when a task matches its description.

Can I use Corvus Typed Model Construction in Cursor, Gemini CLI or GitHub Copilot?

Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add corvus-dotnet/Corvus.JsonSchema --skill corvus-typed-model-construction -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/corvus-typed-model-construction, .gemini/skills/corvus-typed-model-construction, .github/skills/corvus-typed-model-construction and .opencode/skills/corvus-typed-model-construction in your project.

What does Corvus Typed Model Construction need to run?

SKILL.md names no scripts, command-line tools or credentials: Corvus Typed Model Construction is instructions for the agent only.

Does Corvus Typed Model Construction access the network?

SKILL.md contains no URLs. Any network use would come from the scripts or tools the agent runs. This is read from the text; nothing was executed.

Is Corvus Typed Model Construction safe to install?

Our automated static check of SKILL.md found no risky patterns, such as piping downloads into a shell, reading credential files or hidden Unicode. It is not a guarantee. Review the folder before installing.

What licence does Corvus Typed Model Construction use?

Corvus Typed Model Construction is published under the Apache-2.0 licence (the repository's licence). It allows redistribution, so the full SKILL.md is shown on this page.

How many tokens does Corvus Typed Model Construction use?

About 2.4k tokens (SKILL.md is roughly 9.8k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full.

What are the alternatives to Corvus Typed Model Construction?

Skills that share tags, products or a category with Corvus Typed Model Construction: Chroma Vector Database (Orchestra-Research/AI-Research-SKILLs, 13k stars), SageMaker Serving Image Selection (huggingface/skills, 11k stars), Codebase Management (giancarloerra/SocratiCode, 3.3k stars) and CLIP Image-Text Matching (Orchestra-Research/AI-Research-SKILLs, 13k stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains Corvus Typed Model Construction?

corvus-dotnet (a GitHub organization) maintains it in corvus-dotnet/Corvus.JsonSchema, which has 199 GitHub stars. The repository holds 28 skills in this directory. The repository was last updated on October 9, 2026.

Source: corvus-dotnet/Corvus.JsonSchema on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.