SGF File Format

Smart Game Format (SGF) is a loosely defined file format, and as such, there are many varieties depending on the application that created them. OGS creates .sgf files in a flavor for download, and accepts various flavors of it for upload, but 100% compatibility cannot be guaranteed.

Here is what I found in a recent struggle to upload a file. I decided to post it here, so that others will have easier time fixing the compatibility issue.

  1. SGF file is a text file, so it can be opened, edited and saved with a text editor.

  2. Although the entire SGF spec may be a bit complicated with several versions of definition it went through, the key requirements are simple.

  3. When you satisfy the required fields (combination of data name and data in NAME[data]; format), and their order in the file, most compatibility issues are resolved.

    OGS Format
(;FF[4]GM[1]DT[2015-03-13]PC[OGS: http://online-go.com/game/1698068]
PB[Kugutsu]PW[anonymous]BR[12k]WR[1d]CP[online-go.com]
RE[B+7.5]SZ[19]KM[6.5]RU[japanese];
B[qc];W[pp];B[dq];W[dd];B[jj];W[co];B[fp];W[cq];B[cr];W[dp];
B[eq];W[bq];B[jq];W[dj];B[np];W[nq];B[mq];W[oq];B[mp];W[qn];
B[fc];W[jc];B[db];W[fd];B[gc];W[ec];B[eb];W[oc];B[pe];W[oe];
B[pf];W[pd];B[qd];W[gd];B[fj];W[fi];B[jh];W[ii];B[ih];W[ji];
B[ki];W[ij];B[gi];W[gj];B[ei];W[fh];B[hj];W[gk];B[ik];W[gh];
B[hi];W[fm];B[ej];W[dk];B[di];W[dg];B[gl];W[fk];B[fl];W[ek];
B[gm];W[on];B[nn];W[nm];B[kd];W[kc];B[ld];W[mc];B[ie];W[qh];
B[lc];W[lb];B[mn];W[rf];B[re];W[qf];B[qe];W[pj];B[mm];W[nl];
B[cc];W[cd];B[el];W[dl];B[en];W[dn];B[em];W[hc];B[gb];W[pb];
B[mj];W[bd];B[bc];W[hb];B[qb];W[ga];B[pc];W[od];B[nb];W[ob];
B[mb];W[la];B[nc];W[md];B[nd];W[me];B[ne];W[nf];B[mf];W[na];
B[le];W[ma];B[of];W[oa];B[mr];W[nr];B[fb];W[eo];B[fo];W[ac];
B[ab];W[ad];B[bb];W[ml];B[ll];W[ms];B[ls];W[ns];B[lr];W[br];
B[dr];W[nj];B[ni];W[oi];B[nh];W[mk];B[lk];W[qa];B[sf];W[sg];
B[rg];W[qg];B[sh];W[rh];B[sg];W[si];B[se];W[rj];B[ra];W[he];
B[hf];W[gf];B[oh];W[ph];B[oo];W[po];B[om];W[pn];B[ok];W[oj];
B[nk];W[pk];B[ol];W[pl];B[hg];W[id];B[jd];W[fa];B[dc];W[ed];
B[dm];W[cm];B[ep];W[do];B[gg];W[fg];B[op];W[ea];B[da];W[ha];
B[pm];W[qm];B[hk];W[pg];B[bs];W[ar];B[og];W[as];B[cs];W[ff];
B[pq];W[pr];B[pa];W[kb];B[qa];W[hh];B[if];W[];B[qq];W[qr];
B[qp];W[rr];B[];W[])
    One example of non-OGS file accepted by OGS server
(;FF[4]CA[UTF-8]AP[GoGui:1.4.9]
KM[6.5]SZ[19]PB[Hirofumi Ohashi]BR[6p]PW[Toramaru Shibano]WR[1p]
EV[Japan National Team Training Match]
DT[2014/11/15]RE[W+R]RU[Japanese]
PC[Internet, "Yugen no Ma" (Nihon Kiin)]US[Tokumoto]PL[B];
B[mg];W[dp];B[gm];W[dd];B[mm];W[pp];B[gg];W[pd];B[nq];W[qn];
B[pr];W[qk];B[nc];W[qf];B[pb];W[ph];B[fq];W[cn];B[dr];W[ck];
B[fc];W[df];B[cc];W[dc];B[db];W[eb];B[cb];W[ec];B[be];W[fd];
B[hd];W[bf];B[ce];W[cf];B[cd];W[de];B[qq];W[kd];B[jf];W[md];
B[nd];W[ne];B[me];W[kf];B[oe];W[nf];B[mf];W[je];B[if];W[kg];
B[fe];W[ie];B[he];W[ig];B[hf];W[ki];B[lh];W[ii];B[gi];W[mc];
B[mb];W[lb];B[nb];W[ic];B[og];W[pg];B[pf];W[hc];B[qe];W[pe];
B[of];W[re];B[pi];W[qd];B[qj];W[oh];B[pk];W[ql];B[nk];W[qb];
B[ro];W[oj];B[oi];W[nh];B[ng];W[nj];B[ni];W[mi];B[mj];W[mk];
B[lj];W[li];B[pc];W[qc];B[kh];W[lk];B[kj];W[ok];B[ol];W[nl];
B[pj];W[nk];B[pl];W[nm];B[pn];W[jj];B[nn];W[kk];B[kb];W[kc];
B[la];W[lc];B[od];W[on];B[oo];W[om];B[pm];W[po];B[qm];W[op];
B[no];W[np];B[lo];W[mp];B[kp];W[mo];B[mn];W[ln];B[lm];W[kn];
B[km];W[ko];B[jp];W[jn];B[jm];W[in];B[im];W[hn];B[lp];W[hm];
B[mq];W[il];B[qo];W[fh];B[dk];W[dl];B[fi];W[eh];B[el];W[fo];
B[eo];W[ep];B[fp];W[fn];B[en];W[fm];B[em];W[cm];B[gk];W[hl];
B[dj];W[cj];B[gd];W[gh];B[fb];W[fa];B[ga];W[ea];B[jg];W[jh];
B[gb];W[jb];B[le];W[ke];B[ka];W[hb];B[hg];W[ih];B[id];W[ma];
B[na];W[jc];B[ff];W[ed];B[gc];W[fg];B[ja];W[ia];B[ma];W[ha];
B[cq];W[cp];B[hp];W[ae];B[ad];W[af];B[ab];W[ri];B[rj];W[hh];
B[lg];W[ef];B[lf];W[ge];B[ld];W[ee];B[gf];W[bq];B[br];W[bp];
B[rh];W[rg];B[si];W[ar];B[qa];W[ra];B[pa];W[rb];B[bs];W[ho];
B[go];W[gn];B[gp];W[eq];B[er];W[ip];B[iq];W[jo];B[io];W[dq];
B[cr];W[ip];B[bl];W[cl];B[io];W[bd];B[bc];W[ip];B[jl];W[hq];
B[io];W[jk];B[oq];W[ip];B[gr];W[jq];B[io];W[qh];B[qi];W[ip];
B[ir];W[lq];B[io];W[jd];B[ib];W[ip];B[hj];W[kq]C[Black resigns])

ref: B=black, W=white, FF=file format version, CA=encoding, AP=application
KM=komi, SZ=size, PB=black player name, BR=black player rank,
PW=white player name, WR=white player rank, EV=event name,
DT=date, RE=game result, RU=game rule name, PC=location,
US=file creator/user name, PL=initial player color, C=comment,
CP=copyright, GM=game type (Go is 1)

6. Sources of info:

http://www.red-bean.com/sgf/
http://www.red-bean.com/sgf/sgfc/
(the last link is for a file converter, but I’ve found the manual method using a text editor is far simpler and convenient)

1 Like

I wouldn’t say that SGF is “loosely defined”. In fact, the spec that you link to (SGF file format FF[4]) is quite thorough and precise. There have been changes to the format over time, but these changes have been well-documented and there is even a guide on how to properly convert files up to the latest version (see SGF FF[4]: Converting old SGF files to FF[4]). The latest version FF[4] was introduced in 2006, and overall the standard seems quite stable as it has not been updated since then.

The “many different varieties” are not due to the SGF standard being “loosely defined” (which it is not), but rather are due to various applications not properly complying with the SGF standard.

I’m not familiar with the behavior of OGS SGF upload/import (since I have not used that feature), but I have seen that OGS creates SGF files for export/download that violate the SGF standards. Here is a separate thread where I document some of these bugs:

1 Like