Skip to main content

Refrase

Your prompts, upgraded.

PyPI npm License: MIT Tests

Refrase optimizes your AI prompts for specific models using research-backed, model-specific formatting rules. No LLM required — it's deterministic and instant.

Why?

Most developers write one prompt and hope it works on every model. But models were trained on different data with different RLHF processes. Claude works best with XML tags. Qwen3 needs /think prefixes. Mistral's Magistral emits [TOOL_CALLS] markers that break JSON parsing. Refrase handles all of this automatically.

Quick Start

Python

pip install refrase
import refrase

result = refrase.adapt(
    "You are a helpful data analyst. Extract all key metrics from the report.",
    model="claude-sonnet",
    task="extraction",
)

print(result.system)
# <role>
# You are a helpful data analyst.
# </role>
#
# <instructions>
# Extract all key metrics from the report.
# </instructions>
#
# <output_format>
# Return structured output matching the schema.
# </output_format>

print(result.changes)
# [Change(rule='xml-structure', description='Restructured prompt with XML tags', ...)]

TypeScript

npm install refrase
import { adapt } from "refrase";

const result = adapt({
  prompt: "You are a helpful data analyst. Extract all key metrics.",
  model: "claude-sonnet",
  task: "extraction",
});

console.log(result.system);
console.log(result.changes);

Before / After

Model Before After
Claude Sonnet Plain text prompt XML-tagged <role>, <instructions>, <output_format>
Qwen3 32B No thinking directive /no_think prefix + Tier 3 JSON reinforcement + English enforcement
Magistral Standard prompt Suppressed [TOOL_CALLS] and [THINK] markers + ultra-strong JSON-only
GLM 4.7 Flash Verbose prompt Simplified + nested object fix + English enforcement
Nemotron 9B Full prompt /think prefix + simplified to 3 steps + Tier 3 JSON reinforcement

Supported Models

11 model families, 39+ model variants:

Family Models Key Adaptations
Claude Sonnet, Opus, Haiku XML tags, role extraction, Haiku simplification
OpenAI GPT-4o, o1, o3 Reasoning hints, grounding rules
Gemini Pro, Flash, Ultra Identity (baseline — no changes)
Qwen 235B, 32B, Coder Thinking mode, Tier 3 for 32B, English enforcement
DeepSeek V3, V3.1, V3.2 Self-verification, JSON reinforcement
Mistral Large, Magistral, Devstral, Ministral Marker suppression, type fixes, simplification
Llama 405B, 70B, 8B, 3B Grounding, small model simplification
Kimi K2, K2.5 Source grounding, English enforcement
GLM 4.7, 4.7 Flash Nested object fix, English, Flash simplification
Nemotron 30B, 12B, 9B Thinking mode, Tier 3 for small, simplification
MiniMax M2 Self-verification, contract-style

Task Types

Task When to Use
extraction Pulling structured data from documents
analysis Evaluating, comparing, or reasoning about data
generation Creating content, writing, summarizing
code Writing or reviewing code
general Everything else (default)

MCP Server

npm install -g @refrase/mcp-server

Add to your MCP config:

{
  "mcpServers": {
    "refrase": {
      "command": "refrase-mcp-server"
    }
  }
}

Adding New Model Adapters

See CONTRIBUTING.md for a 5-step guide to adding support for new models.

Research

Refrase's adaptation rules are derived from empirical testing across 46 model configurations on structured output tasks. Research paper coming soon.

License

MIT

Metadata

Release files for refrase 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for refrase 0.1.0
File Size Uploaded Provenance Actions
refrase-0.1.0.tar.gz 17.0 kB Without provenance Details for refrase-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for refrase 0.1.0
File Interpreter ABI Platform Actions
refrase-0.1.0-py3-none-any.whl Python 3 none any Details for refrase-0.1.0-py3-none-any.whl

Total release size: 40.4 kB

Release files / refrase-0.1.0.tar.gz

Download URL refrase-0.1.0.tar.gz
Size 17.0 kB
Tags Source
SHA-256 checksum
How to use checksums
3f317fa57c608cc23c4f0a23db2111054cb92d34371a9e651a9f93c546fc3013
BLAKE2b-256 checksum
How to use checksums
53487a868deb898949c0e1d3df64a947ee7e3f6bb8ed407c6eae79612c3526c4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.9

Release files / refrase-0.1.0-py3-none-any.whl

Download URL refrase-0.1.0-py3-none-any.whl
Size 23.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
85607c277ff10c8b0830da26bd3bbd6ef609690e9ad09cf866a3d60c8feec524
BLAKE2b-256 checksum
How to use checksums
441b79e98bd172ba97335e317c77fcfd97756bddd1063a8529728a8d482f7628
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.9

Security for refrase 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page