Contributing to LLM4S
This guide covers everything you need to know before opening your first pull request. Please read it fully — PRs that ignore these guidelines will be closed.
Before Your First PR
- Read this guide and the Code Review Guidelines
- Fork and clone the repository
- Verify your setup — run
sbt buildAllandsbt testto confirm everything compiles and passes - Read
CLAUDE.mdin the repo root — it contains project conventions, architecture notes, and common commands
Picking an Issue
Start Small
Your first PR should be small — under ~200 lines of changes. Pick a good first issue and get familiar with the codebase, the review process, and the project conventions before tackling anything larger.
Good first contributions:
- Add missing unit tests
- Fix a documentation error
- Address a single-file bug fix
- Improve an error message
Comment Before You Start
Before writing code, comment on the issue saying you’d like to work on it. This avoids duplicate effort and lets maintainers give you pointers.
A PR Does Not Need to Solve the Entire Issue
A PR that fixes one module, one pattern, or one aspect of an issue is perfectly valid — and often preferred. For example, if an issue asks to “replace sys.env in all sample files”, a PR that fixes 2-3 files is better than one that tries to fix all 8 at once and gets things wrong.
Complex Issues Need Discussion First
For issues involving architectural decisions, new modules, or cross-cutting changes:
- Read the existing design docs in
docs/design/ - Comment on the issue with your proposed approach
- Wait for maintainer feedback before writing code
- Consider writing a small experiment or proof-of-concept to validate your approach
Maintainers will not assign major architectural work to contributors without a track record in the project. Build trust with smaller PRs first.
The Contribution Ladder
| Level | What | Examples |
|---|---|---|
| 1. Observe | Read code, comment on issues, review others’ PRs | “I think this edge case is missing…” |
| 2. Small fixes | Docs, tests, single-file changes (<200 lines) | Fix a broken link, add a unit test |
| 3. Features | After 1-2 merged PRs, take on larger work | Implement a focused feature from an issue |
| 4. Architecture | Requires design discussion and maintainer sign-off | New module, API redesign, cross-cutting refactor |
Before Submitting Your PR
Run all of these locally before pushing:
1
2
3
sbt scalafmtAll # Format code
sbt test # Tests pass on the current Scala 3.7.1 build
scripts/check-docs.sh # If you changed docs/: every documentation check CI's Quick Checks runs without sbt
Also check:
1
2
git diff --stat # Review the size of your changes — keep it focused
git log --oneline # Are your commit messages clear?
If CI fails on your PR, fix it before requesting review. Do not ask reviewers to look at a red build.
PR Requirements
Size
Keep PRs small and focused. One change, one reason.
- First PRs: aim for under ~200 lines
- Experienced contributors: still prefer under ~500 lines
- If your change is larger, discuss it in the issue first and consider splitting into a chain of smaller PRs
Description
Your PR description must explain:
- What changed
- Why it’s needed (link the issue)
- How you tested it
A PR with just “Add feature X” and no context will take longer to review and may be closed.
Commit Messages
Use imperative mood. Explain the why, not just the what.
1
2
3
4
5
6
7
8
9
10
# Good
Add retry logic for transient 503 errors from OpenAI
Normalize ujson.Null to ujson.Obj() at provider parsing boundaries
Fix resource leak in GeminiClient streaming response handler
# Bad
updated stuff
fix
changes
wip
If your PR has a messy commit history, squash it into clean, logical commits before requesting review.
No Unrelated Changes
Do not bundle unrelated fixes, refactors, or formatting changes into the same PR. If you spot something else that needs fixing, open a separate issue or PR.
A common mistake: creating your branch from another PR’s branch instead of main. This pulls in unrelated commits. Always branch from main:
1
2
3
git checkout main
git pull origin main
git checkout -b your-branch-name
What Gets PRs Closed
PRs will be closed without detailed review if they:
- Don’t compile or pass tests — run
sbt testlocally first - Include unrelated changes from stacked branches (rebase onto
main) - Are very large without prior discussion — start a conversation on the issue first
- Ignore feedback from a previous review round
- Duplicate existing work — check open PRs before starting
- Use patterns banned by the project —
sys.envin core code,throwfor control flow,Anytypes (see Code Review Guidelines)
Reviewer time is limited. PRs that clearly haven’t followed these guidelines waste that time and slow down the entire project.
Code Standards Quick Reference
These are the most common issues found in PR reviews. The full list is in Code Review Guidelines.
Use Result[A], not exceptions
1
2
3
4
5
6
7
8
9
// Good
def parseConfig(json: String): Result[Config] =
if (json.isEmpty) Left(ValidationError("Empty JSON"))
else Right(Config.parse(json))
// Bad
def parseConfig(json: String): Config =
if (json.isEmpty) throw new IllegalArgumentException("Empty")
else Config.parse(json)
Use Llm4sConfig at the app edge, not sys.env
1
2
3
4
5
6
7
8
9
10
// Good — in samples/CLI code
val result = for {
config <- Llm4sConfig.defaultProvider()
registry <- Llm4sConfig.modelRegistryService()
given ModelRegistryService = registry
client <- LLMConnect.getClient(config)
} yield client
// Bad — anywhere
val apiKey = sys.env.getOrElse("OPENAI_API_KEY", "")
See Configuration Boundary and Scalafix Rules for details.
Follow the naming conventions
Factories. The name says where the value comes from; the return type says whether building it can fail. A
factory that can fail returns Result[X], and none throws.
| Name | Builds the value from | Examples |
|---|---|---|
apply |
the type’s own fields | CompletionOptions(), EmbeddingRequest(input, model) |
of |
values that are not simply its fields: the items it holds, the thing it wraps, a raw id | ToolRegistry.of(tools), ConversationTokenCounter.of(tokenizer), AgentId.of("assistant") |
create |
something it has to look up, allocate or check first | ConversationTokenCounter.create(tokenizerId), ContextManager.create(counter), HeadroomPercent.create(0.1) |
from, fromX |
another representation: configuration, JSON, a file, another type | EmbeddingClient.from(cfg), Llm4sConfig.from(config), ArtifactKey.fromContent(text) |
forX |
a key that selects one of several | OpenAITokenizers.counterFor(model) |
new is for a plain class with nothing to check. A type that validates its arguments, or that may gain a field,
has a private constructor and is built through its companion.
Sum types. A closed set of plain values is a Scala 3 enum (Modality, ContextStage). When a case carries
fields it is a sealed trait with one final case class X private per case, each with its companion apply and
with* setters: an enum case with fields has a public constructor and copy, which a new field would break.
Accessors. A method that returns a value is named for the value (usage, contextWindow), not getUsage,
and has no parameter list when it takes no argument (client.contextWindow, not client.contextWindow()). The one
family of get names is a typed read by key, as Map.get and Typesafe Config’s getString are:
SafeParameterExtractor.getString(path), getInt, getOptionalString. A getX left in an @Experimental type
(SemanticBlock.getBlockSummary, TokenWindow.getUsageInfo) predates the rule and is renamed when that type is
next changed.
Constants. PascalCase, as the Scala style guide has it: MaxDepth, DefaultTimeout. The exception is a
constant named after an external identifier, which keeps that spelling (TokenizerId.CL100K_BASE).
Newtypes. An identifier or quantity with its own type is an opaque type with a companion: apply when every
value is valid, create returning a Result when not, and an as... accessor to unwrap it (asString,
asRatio). Use the newtype in a public signature where one exists (ProviderId, ModelName) instead of a
String.
Run scalafmt
1
sbt scalafmtAll
The project uses -Werror (fatal warnings). Formatting issues, unused imports, and deprecation warnings will all fail the build.
Write tests
Every PR with new code needs tests. See the Testing Guide for details.
Development Workflow
Setup
1
2
3
4
5
# Fork the repo on GitHub, then:
git clone https://github.com/YOUR-USERNAME/llm4s.git
cd llm4s
sbt buildAll # Verify everything compiles
sbt test # Verify tests pass
IDE Setup
Minimal setup of your IDE of choice to enable syntax highlighting and IntelliSense.
- VS Code: Scala (Metals) extension
- IntelliJ: Scala plugin
Making Changes
1
2
3
4
5
6
7
8
9
10
11
git checkout main
git pull origin main
git checkout -b fix/short-description # Use a descriptive branch name
# Make your changes...
sbt scalafmtAll # Format
sbt test # Test the current Scala 3.7.1 build
git add <specific-files> # Stage only your changes
git commit -s -m "Fix: short description of what and why" # -s adds the DCO sign-off CI checks
git push origin fix/short-description
Creating the PR
- Push your branch to your fork
- Open a PR against
llm4s/llm4s:main - Fill in the PR template — don’t skip any sections
- Verify CI passes
- Wait for review — don’t ping reviewers unless it’s been several days
After Review
- Address all feedback before re-requesting review
- If you disagree with feedback, explain your reasoning — don’t silently ignore it
- Push new commits (don’t force-push during review — it makes it harder to see what changed)
Getting Help
- Issue questions: Comment on the issue
- Code questions: Ask in Discord
- Stuck on a test: Look for similar tests in the codebase — there are patterns for most scenarios
- Build problems: Check Getting Started for setup instructions
Related Documentation
- Code Review Guidelines — Detailed coding standards with examples
- Testing Guide — How to write tests
- Configuration Boundary — Config architecture
- Scalafix Rules — Automated code quality enforcement
This guide reflects actual project expectations. PRs that follow it get reviewed faster and merged sooner.