Early Beta — The Web SDK is in early beta. APIs may change between releases.
Overview
A system prompt sets the model’s role, tone, and constraints. Pass it assystemPrompt on the
generation options; commons places it correctly for whatever chat template the loaded model uses.
Basic usage
generateStream(), generateStructured(), and the llmOptions channel of
generateWithTools().
Examples
Coding assistant
Concise responder
Persona
Technique reference
Prefer structured output over prompt-only JSON
Asking for JSON in a system prompt gets you JSON-shaped text with no guarantees. When you need a parseable object, use the structured-output verbs instead. They pass a schema into commons, which prepares the prompt, constrains decoding where the backend supports it, and validates the result.generateStructured() sets includeSchemaInPrompt: true by default, so it writes the schema
instructions for you. See Tool calling and structured output.
Guidelines
Keep system prompts short. Every token spent there is a token unavailable to the user’s prompt and the response, which matters on the 350M to 1B models that fit comfortably in a browser tab. Be specific (“You are a Python expert” beats “You are helpful”), put format instructions first, and state what the model should not do as well as what it should.Related
Generate
Full generation with options
Streaming
Real-time token streaming