jac-by-llm

Delegate Jac function bodies to LLM calls with typed returns, tools, and sem prompts.

Updated Jul 26, 2026
One-click install
npx skills add https://github.com/nihalnihalani/jachacks-sf-2026 --skill jac-by-llm-nihalnihalani
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: jac-by-llm
Source: https://github.com/nihalnihalani/jachacks-sf-2026/tree/main/plugins/jac-codex/skills/jac-by-llm
Command: npx skills add https://github.com/nihalnihalani/jachacks-sf-2026 --skill jac-by-llm-nihalnihalani

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Writing LLM-powered features in Jac normally requires manual prompt construction, output parsing, and retry logic. This Skill explains how to replace a function body with by llm(...) so the model generates typed return values directly, with structured outputs, tool use, and testable mocks. ## Core Features & Use Cases - Structured LLM Outputs: Return objects, enums, lists, and optional values from by llm functions, with sem statements serving as the prompt schema the model sees. - ReAct Tool Use: Pass tools=[...] so the model chooses which functions to call across multiple iterations, including bound object methods as tools. - Provider Configuration & Testing: Configure OpenAI, Anthropic, Google, Ollama, or local models via jac.toml and environment variables, and test without API keys using MockLLM. - Use Case: Build a ticket classifier that returns a typed Priority enum, or a ReAct agent that answers questions by calling a word_count tool, then verify both with MockLLM outputs in jac test. ## Quick Start Ask the AI to write a Jac function that summarizes text into a typed Summary object using by llm with sem descriptions for the function and each field.

Frequently Asked Questions about jac-by-llm

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I make an LLM return structured output in Jac?▼

Declare a function with a typed return such as an obj, enum, or list, and end the signature with `by llm(...)` instead of a body. Describe the function, parameters, and each return field with `sem` statements, which form the prompt schema the model sees.

How do I give an LLM function tools to call in Jac?▼

Pass function references in `tools=[...]`, for example `by llm(tools=[word_count])`, which activates a ReAct loop where the model chooses when to call each tool. Each tool needs its own `sem` and per-argument `sem` so the model knows when to use it.

Which model providers does byLLM support in Jac?▼

byLLM supports OpenAI, Anthropic, Google Gemini, Ollama, and a built-in local model option. Configure the default in `jac.toml` under `[byllm.model]` or override per file with a module-level `glob` holding a `Model` instance; API keys come from environment variables.

How do I test by llm functions without API keys?▼

Use MockLLM from `jaclang.byllm.lib` with a `config` containing an `outputs` list, which is consumed sequentially per `by` call. For typed returns, place pre-built instances like enum members or object lists in `outputs` and assert results in `jac test`.

Why does my by llm function fail at runtime?▼

Common causes include writing both a body and `by llm` on one signature, passing tool names as strings instead of function references, or misspelled `by llm` options that `jac check` does not validate. Typed returns auto-retry malformed output up to `max_output_retries` times before raising `OutputConversionError`.

Can by llm functions process images or video?▼

Yes, accept `Image` or `Video` parameters from `jaclang.byllm.lib` and return structured output directly, using a vision-capable model such as gpt-4o. Video requires installing the `byllm[video]` extra and supports an `fps` sampling parameter.